|
-
June 23rd, 2004, 01:31 AM
#3
Ok, I got the answer I want. Now, I want to share the code here
Code:
void GetReverseByteOrder(int n) {
union {
int nGiven;
unsigned char val[4];
} HEXA;
HEXA.nGiven = n; /* n is input of user */
for (int i=0; i<4; i++)
printf("%02x",HEXA.val[i]);
}
What does this piece of code do?
-- user types in a number, say 123456
-- 123456 is stored to n and passed to HEXA.nGiven
-- we know that 123456 is 1E240 in base 16
-- now, we wanted to reverse 1E240 making it 40E20100
-- 40E20100 is generated by the code above
How come? Can u imagine how? :-)
That's it! A generous man from codeguru shared the above code. I just did a little modification. I forgot his username here in this forum but anyway, many many thanks to him!
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
|