solved  Parse the hex digits of int?

scienceskillz (6)   Link to this post
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
Bazzy (3168)   Link to this post
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

Registered users can post in this forum.