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

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