Skip to content

Commit

Permalink
Add color converter test program
Browse files Browse the repository at this point in the history
  • Loading branch information
RoccoLoxPrograms committed Apr 15, 2022
1 parent 2026791 commit ed94eb7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
1555ColorPicker.html
ColorConverter/*.exe
22 changes: 22 additions & 0 deletions ColorConverter/ColorConvert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdint.h>

int main(void) {
unsigned int color;
unsigned int red;
unsigned int green;
unsigned int blue;
printf("Enter RGB565 value: ");
scanf("%x", &color);
red = ((((color >> 11) & 0x1F) * 527) + 23) >> 6;
green = ((((color >> 5) & 0x3F) * 259) + 33) >> 6;
blue = (((color & 0x1F) * 527) + 23) >> 6;
printf("Red: %d\n", red);
printf("Green: %d\n", green);
printf("Blue: %d\n", blue);
uint32_t rgbHex = red << 16 | green << 8 | blue;
printf("Hex: %x\n", rgbHex);
uint16_t rgb565 = ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
printf("RGB565 value: %x", rgb565);
return 0;
}

0 comments on commit ed94eb7

Please sign in to comment.