View previous topic :: View next topic |
Author |
Message |
pr83
Joined: 20 Jul 2006 Posts: 15
|
Bit Conversion |
Posted: Tue Jan 02, 2007 6:59 pm |
|
|
I have a 16 bit variable. How do I convert it into a 8 bit variable such that the 8 bit variable contains the bits(10,9,8,7,6,5,4,3,2) of the 16 bit variable.
Any suggestions!! |
|
|
Guest
|
|
Posted: Tue Jan 02, 2007 7:37 pm |
|
|
Hi,
How about ANDing the 16 bit value with 0x03FC to strip off the lower two bits and the upper six bits, and then shift the result two places to the left?
That's something I'd try!
Tim |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Tue Jan 02, 2007 8:33 pm |
|
|
Yes, logical "and", then shift, or, just shift and assign to an 8-bit variable:
x8 = y16 >> 2;
But I'm afraid you'll still have trouble stuffing 9 bits into an 8-bit variable (count 'em)
Ken |
|
|
Guest
|
|
Posted: Wed Jan 03, 2007 11:19 am |
|
|
I tried manipulating 0x0F1F (16 bits) variable such that the new 8 bit variable would be 11000111. I tried to use shift_left(), but I always ended up with 0x01.
Any suggestions!! |
|
|
Guest
|
|
Posted: Wed Jan 03, 2007 11:34 am |
|
|
Yes, post your code! At this point, we can't help without seeing specifically what you are doing!
Ian |
|
|
Guest
|
|
Posted: Wed Jan 03, 2007 3:30 pm |
|
|
It works now. I didnt use the '&' sign for address, and it didnt know which address to start from for the 2 bytes under consideration.
Thank You though. |
|
|
|