Getting Last Two Bytes
-
Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,
-
Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,
Hello Ratheesh, You can use LOWORD()[^] macro to get the last two bytes together. If you need last two bytes separately, then call LOWORD()[^] to get last two bytes together and then get bytes separately by calling LOBYTE()[^] and HIBYTE()[^] macros. Regards, Jijo.
_____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
modified on Friday, June 12, 2009 7:43 AM
-
Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,
ratheeshnair123 wrote:
last two bytes
it is a bit ambiguous... :rolleyes:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,
You can also achieve the results using & and shift-operators. Something like unsigned-var & 3 (as last 2 bits are 1s and all others are 0s) and then do left-shift to get last 2 bits.
-
You can also achieve the results using & and shift-operators. Something like unsigned-var & 3 (as last 2 bits are 1s and all others are 0s) and then do left-shift to get last 2 bits.
no need to left shift the bits. they are already in the required order.
regards :)
-
Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,
Another option is to use the modulus operator:
int i = 0;
int x = 0;
i = 1286439; // i is now 0x13A127
x = i % 65536; // x is now 0xA127Just another way to do the same thing.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193