cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Parse the hex digits of int?
Parse the hex digits of int?
Nov 4, 2009 at 9:31pm UTC
scienceskillz
(8)
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
Nov 4, 2009 at 9:37pm UTC
Nov 4, 2009 at 9:36pm UTC
Bazzy
(6281)
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.