Shop OBEX P1 Docs P2 Docs Learn Events
need help parsing out a long.. probably simple — Parallax Forums

need help parsing out a long.. probably simple

laser-vectorlaser-vector Posts: 118
edited 2010-11-05 15:46 in Propeller 1
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???

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-11-05 15:19
    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 ChapT Chap Posts: 4,223
    edited 2010-11-05 15:46
    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
Sign In or Register to comment.