-
February 24th, 2009, 08:27 AM
#1
4bytes int to 2bytes int conversion
Hi...
In C, I have int data type of 4 bytes...
but I have to consider the lower 2 bytes only & have to put higher 2 bytes in another int
Can any body tell me how to cast the int4 bytes to int2 bytes???
-
February 24th, 2009, 08:34 AM
#2
Re: 4bytes int to 2bytes int conversion
Hi!
Code:
int myint = ...;
//low bytes:
short low = myint & 0xFFFF;
//high bytes:
short high = myint >> 8;
Nobody cares how it works as long as it works
-
February 24th, 2009, 09:01 AM
#3
Re: 4bytes int to 2bytes int conversion
Thank you for the help....
I could solve it using char...... :
Anyways thank you!!!
-
February 24th, 2009, 10:39 AM
#4
Re: 4bytes int to 2bytes int conversion
You could use the LOWORD and HIWORD macros too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|