-
-
Save rbricheno/911bdccdcdc103673e0f75ec0eac75d7 to your computer and use it in GitHub Desktop.
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 characters
/* | |
https://stackoverflow.com/a/53966346/9794932 | |
https://tio.run/##TZDrToQwEIX/9ylOMG6KgqHrbc0Cibd9CeTHAkWarIUsRaubfXbsRY1Nk5n2nMl8M3Ws6nqe33vRoFK9pnW33eNMDxHqXo4K/l1VEYRUkCHIgcCcf6rWRZkhSNjy8ur65nZ1d//w@PS8CdbO@NGJHQeNY4k8QxJCD4UskdkyWlWFzHNWIs9BKUMMKhcsDJGmWJqwQKI35ZocCTkRst5NDUc6qkb0F11OiPoceMNbTHIUr5I3nmcypKs1IW6ot62Q1GZ/5E5GNbWFpTgkEZi5NrCjR3aTGm0UX7xvrdXyMC@6Fh3Xo9oXEudgBs8Jbn1eiGxNZLblS37dtl/iv4a9adLS4HR8kUH04zD24zx/Aw | |
*/ | |
void btox(char *xp, const char *bb, int n) | |
{ | |
const char xx[]= "0123456789ABCDEF"; | |
while (--n >= 0) xp[n] = xx[(bb[n>>1] >> ((1 - (n&1)) << 2)) & 0xF]; | |
} | |
/*****/ | |
#include <stdio.h> | |
typedef unsigned char uint8; | |
void main(void) | |
{ | |
uint8 buf[] = {0, 1, 10, 11}; | |
int n = sizeof buf << 1; | |
char hexstr[n + 1]; | |
btox(hexstr, buf, n); | |
hexstr[n] = 0; /* Terminate! */ | |
printf("%s\n", hexstr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment