fork download
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <limits.h>
  5.  
  6. static size_t itohexa_helper(char *dest, unsigned x) {
  7. size_t ret = x >= 16 ? itohexa_helper(dest, x / 16) : 0;
  8. dest[ret] = "0123456789abcdef"[x & 15];
  9. return ret + 1;
  10. }
  11.  
  12. size_t itohexa(char *dest, unsigned x) {
  13. size_t ret = itohexa_helper(dest, x);
  14. dest[ret] = '\0';
  15. return ret;
  16. }
  17.  
  18. int main(void) {
  19. char array[8];
  20. uint16_t temperature = 0x1f11;
  21. itohexa(array, temperature);
  22. puts(array);
  23. itohexa(array, 0);
  24. puts(array);
  25. itohexa(array, 0x1234567);
  26. puts(array);
  27. itohexa(array, UINT_MAX & 0xFFFFFFF);
  28. puts(array);
  29. }
Success #stdin #stdout 0s 10320KB
stdin
Standard input is empty
stdout
1f11
0
1234567
fffffff