Parse the hex digits of int?

Hi all,

Any idea how to do the following in c++


An integer is entered ie (1320)

int mynum = 1320;

char highbyte;
char lowbyte;

What I need to accomplish....

highbyte = 0x05;
lowbyte = 0x28;

since 0x0528 = 1320;

Thanks!
Last edited on
You can get the last byte with mynum & 0xFF, the other one with ( mynum >> 8 ) & 0xFF
& is bitwise AND http://en.wikipedia.org/wiki/Bitwise_AND#AND
>> is bit shifting http://en.wikipedia.org/wiki/Arithmetic_shift
Topic archived. No new replies allowed.