View Full Version : bit order inverting
Macgman2000
- 27th July 2005, 16:27
Hello,
What is the quickest way to invert the order of bits in an 8bit register? Currently I have data that is essentially backwards in order...IE, LSB is in the MSB poisition and MSB is in the LSB position.....
TempVar = 11011010, I want to flip it to this FinalVar= 01011011
Best Regards,
Nick
mister_e
- 27th July 2005, 16:38
in a loop.. well i guess.
for BitToShift=0 to 7
FinalVar.0[7-BitToShift]=InitialVar.0[BitToShift]
next
There's probably a tons of way but this is the first who comes..
Dwayne
- 27th July 2005, 16:56
Hello Nick,
Nick
What is the quickest way to invert the order of bits in an 8bit register? Currently I have data that is essentially backwards in order...IE, LSB is in the MSB poisition and MSB is in the LSB position.....
TempVar = 11011010, I want to flip it to this FinalVar= 01011011
First off:
to invert the bits you subtract from 255
TembVar=255-TembVar
11011010 would become 00100101
Second off:
Your example is NOT a switch of LSB/MSB
11011010 would be 10101101
The Rev command could be used.... you would reverse bits.
(right out of the manual)
B0 = %10101100 REV 4 (You would use 8)
Your example shows this... Is this what you want?
Edit: (I notice Steve and I were looking at the exact same forum thread in which we were playing with reversing strings....) Steve you is fast!
DWayne
mister_e
- 27th July 2005, 17:01
Dwayne...you're not only hearing impaired, your blind too ROFL... just kidding
TempVar = 11011010, I want to flip it to this FinalVar= 01011011
Bit7 will be Bit0 and so on
Edit: (I notice Steve and I were looking at the exact same forum thread in which we were playing with reversing strings....) Steve you is fast!
Sometime i just sit in the Who's online and look what's happening... no secret :)
BUT Yeah you're right REV will do the job. I never used it before 'cause i never had to swap bits. YEAH STEVE RTFM!!!
I post this picture for me...
Macgman2000
- 28th July 2005, 03:37
Actually I clocked in data to a Temp Variable. The data came in lsb first. So in actuality I want the mirror image of the bit order. Example:
TempVar=11000001....this was shifted in lsb first, 8x so lsb is now in msb position.
I want it to be msb in msb position......FinalVar=10000011. I will try out your suggestion. Thanks!
Best Regards,
Nick
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.