Shop OBEX P1 Docs P2 Docs Learn Events
Hex Math Problem — Parallax Forums

Hex Math Problem

L_GamindeL_Gaminde Posts: 29
edited 2011-06-01 12:20 in BASIC Stamp
Im having trouble with the code below, Im receiving serial data from a device in hex. the data is something like ;9CN0F the 9C part is what i need the 0F is checksum of the first four items so what I did is seed the data into a highnib and lownib of a variable this is how I was going to grab the serial data for this one byte since they come in one at a time. Im getting 23.6 and it should be 48.6 at the end of the serial data, the dec out is correct 156 but the outcome of the math is not, if I seed the data of 156 it works fine ???

' {$STAMP BS2}
' {$PBASIC 2.5}

X1 VAR Byte
X2 VAR Word
X3 VAR Byte

START:
PAUSE 1000
SEROUT 6,16468,[254,1]
PAUSE 1000

X1.HIGHNIB = $9
X1.LOWNIB = $c

X3 = X1
X1 = X1 */$0329
X2 = X1 /10

SEROUT 6,16468,[DEC X3,"   ",DEC X2,".",DEC1 X1  ]

GOTO START

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-06-01 09:39
    Hi Larry,
    X1 needs to be a word, because 156 * / $329 will be greater than 256.

    The decimal value of $9C is 156, agreed, but it looks to me that the answer should be 49.2 or 49.3, not 48.6.
  • L_GamindeL_Gaminde Posts: 29
    edited 2011-06-01 09:49
    Hi Tracy your correct (Duh)
    I had it working last night changed the var type and forgot GEEZ
    yes it should be 49.2 or 3 I was working off the top of my head
    didn't know you were still around and I got busted.

    Thank you Tracy
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-06-01 11:48
    hehe. No to worry. That's the kind of duh variable size thing I do myself all the time. What is the project?
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-06-01 11:50
    hehe. Not to worry. That's the kind of duh variable size thing I do myself all the time. What is the project?
  • L_GamindeL_Gaminde Posts: 29
    edited 2011-06-01 12:20
    Im talking to a Curtis EV controller (this one is a golf cart controller but they all speak the same language) this is the voltage as read by the controller, Im looking at reading all the data out to a hand held or dash mount device motor amps, sensor data, pedal position etc.
Sign In or Register to comment.