How do you reverse the 2nd lot of 8 bits only!
DavidM
Posts: 630
HI,
how do you just rotate the 2nd lot of 8 bits (bits 8-16 or really bits 7-15 ) and leave the first 8 bits ( 0-7 ) alone?
eg
11110000_11110000
needs to be
00001111_11110000
I can reverse the whole thing by using ><16
or I can reverse just the first 8bits by using ><8
but I can't just reverse the 2nd lot of 8 bits! (That is, the 8 bits on the left)
Do I need to split up the "string" of bits into just 8 bit segments and join them together after I manipulate them?
regards
Dave Metus
how do you just rotate the 2nd lot of 8 bits (bits 8-16 or really bits 7-15 ) and leave the first 8 bits ( 0-7 ) alone?
eg
11110000_11110000
needs to be
00001111_11110000
I can reverse the whole thing by using ><16
or I can reverse just the first 8bits by using ><8
but I can't just reverse the 2nd lot of 8 bits! (That is, the 8 bits on the left)
Do I need to split up the "string" of bits into just 8 bit segments and join them together after I manipulate them?
regards
Dave Metus
Comments
Graham
I will try that!
Regards
Dave M
·
N := N & $FF | N >> 8 >< 8 << 8
·
That should do what you want.
·
N & $FF preserve the LSB 8-Bits
·
N >> 8·RIGHT shifts the MSB 8-Bits (temporarily) into the LSB 8-Bits
·
>< 8 reverses the LSB 8-Bits
·
<< 8·LEFT shifts the LSB 8-Bits back into the MSB 8-Bits
·
the | symbol "OR"'s the LSB 8-Bits with the MSB·8-Bits, reconstructing the value of N
·
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
x := x >< 16 >< 8 >< 16.
Here's a way to do it without shifting and masking, not really recommended unless you want to confuse whoever has to look over your code six months from now.
x := (x >< 8 >< 8) | (x >< 16 >< 8 >< 16)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
regards
Dave M