hex to dec to binary
Can anyone tell me how to convert from hex to binary(8bit and 16 bit).
Also I want a convertsion from dec to binary.
Binary back to hex.
I am writing an assembler and I need some function to accomplish this.Are there any c library functions?
Thanks in advance.
You can use ultoa to get them into string format.
I'm not aware of any library functions that do the conversions directly. They wouldn't be too hard to write yourself though.
You can use sprintf or printf to convert to a hex string, and strtoul or strtol to convert a hex string to an int.
There's no standard library functions to convert a number to a binary string. It's easy to write your own by using bit shifting and masking.
unsigned int num = 0xffffffff;
sprintf(hex_str, "%X", num);
num = strtoul(hex_str, NULL, 16);