fork(2) download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. uint16_t floatToRGB565(float input)
  4. {
  5. uint8_t x = input*255;
  6. uint8_t r = (x&248u);//0xff-0x07, 5msb
  7. uint8_t g = (x&252u);//0xff-0x03, 6msb
  8. uint8_t b = (x&248u);//0xff-0x07, 6msb
  9.  
  10. return (r<<8)|(g<<3)|(b>>3);// assuming r is at msb
  11. }
  12.  
  13. int main(void) {
  14. // your code goes here
  15. printf("%u\n", (unsigned int)floatToRGB565(1.0));
  16. printf("%u\n", (unsigned int)floatToRGB565(0.5));
  17. printf("%u\n", (unsigned int)floatToRGB565(0.0));
  18. return 0;
  19. }
  20.  
  21.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
65535
31727
0