PDA

View Full Version : I need help with manipulating bits within a LONG INTEGER!



DavidM
09-07-2007, 11:08 AM
HI,

I need help with manipulating bits within a LONG INTEGER!

I am receiving back a "string" of bits from a SHIFT REGISTER routine.
This uses 3 X 8 BIT shift registers ( 74HC165) chained together to get the states of 24 push buttons. I have no problems getting the data from the shift registers.

By data returns looks like this..
%10000000_00000000_00000000 is equal to button 1 being pressed,
%01000000_00000000_00000000 is equal to button 2 being pressed , and
%00000000_00000000_00000001 is equal to button 24 being pressed and so on

I am storing this value in a LONG INTEGER VARIABLE called InputByteValue
VAR LONG InputByteValue, is my variable definition.

What I WANT to do is to REVERSE the BITS so I get the following instead..

%00000000_00000000_00000001 would be equal to button 1
%00000000_00000000_00000010 would be equal to button 2, and
%10000000_00000000_00000000 would be equal to 24

According to the SPIN MANUAL is should be using the <> operator ( Bitwise reverse )

So I tried this

InputByteValue<>=

and also

InputByteValue<>=24

but I don't get the expected results I want!

Is this something to do with the fact that a LONG INTEGER can hold a value greater that 32bits allows? yet I am only assuming I am working with 24 bits?

Can any one help


regards

Dave M

Skogsgurra
09-07-2007, 11:50 AM
Hello!

Great chip, isn't it.

The only problem I see is that Bitwise reverse is not <> but ><. The <> is the NOT EQUAL operator. Page 268 in the Propeller shows a couple of very clear examples on how to use this operator. In your case, it would be X ><= 24.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

DavidM
09-07-2007, 12:23 PM
Thanks Skogsgurra,

yes Its a great chip and you are right, the brackets need to go the other way!

Thanks

Dave M