Hex Math Problem
L_Gaminde
Posts: 29
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
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.
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