PDA

View Full Version : need help parsing out a long.. probably simple



laser-vector
11-05-2010, 11:12 PM
hi!

im building an application with labview to control a few things in my propeller.

labview sends out a string of bytes that the propeller interprets and compiles into a long.

in this example each bit after the 8 most significant bits represents a boolean condition, and the 8 msb's represent a number... so

databyte = 43
if button one is true,
LONG1 = %00101011_00000000_00000000_00000010

databyte = 46
if button one and two are true,
LONG1 = %00101110_00000000_00000000_00000110

databyte = 0
if button nineteen is true,
LONG1 = %00000000_00001000_00000000_00000000

so now i need to figure out a way to sample LONG1 to see the state of these bits and retrieve the value of the 8 msb's.

any ideas???

Phil Pilgrim (PhiPi)
11-05-2010, 11:19 PM
You can retrieve the value of the data byte by using a shift operator, like this:


value := data_long >> 24

The individual status bits can be tested like so:


if (data_long & |< bit_position)

-Phil

T Chap
11-05-2010, 11:46 PM
You can access a particular byte within the Long like this:

value := Long1.byte[0] 'lsb
value := Long1.byte[1]
value := Long1.byte[2]
value := Long1.byte[3] 'msb