Created
January 29, 2022 17:52
-
-
Save MuntashirAkon/6eb814fc19f53359aee0e4ef81bd074f to your computer and use it in GitHub Desktop.
Revisions
-
MuntashirAkon created this gist
Jan 29, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ // Get a byte array as a hexadecimal character string int hexify(const uint8_t *in, size_t in_size, char *out, size_t out_size) { if (in_size == 0 || out_size == 0) return 0; char map[16+1] = "0123456789ABCDEF"; int bytes_written = 0; size_t i = 0; while(i < in_size && (i*2 + (2+1)) <= out_size) { uint8_t high_nibble = (in[i] & 0xF0) >> 4; *out = map[high_nibble]; out++; uint8_t low_nibble = in[i] & 0x0F; *out = map[low_nibble]; out++; i++; bytes_written += 2; } *out = '\0'; return bytes_written; }