Let’s say i have this number
int x = 65535;
Which is the decimal representation of:
ÿÿ
I know how i can do it from single char
#include <stdio.h>
int main() {
int f = 65535;
printf("%c", f);
}
But this will only give me “ÿ”
I would like to do this without using any external library, and preferably using C type strings.
Consider the value 65535, or 0xffff in hexadecimal, meaning its positive value takes 2 bytes that are 0xff and 0xff
f & 0xffkeeps only the 8 LSb, (0xffff & 0xff = 0xff)f >> = 8shifts the value 8 bits to the right, 0xffff becomes 0x00ff (the ‘ff’ right side are gonef > 0is true sincef == 0xffnowNext loop is the same, but
f >>= 8shifts 0x00ff to the right => 0x0000, and f is null.Thus the
f > 0condition is wrong and the loop ends.