How do I convert the hex value from a buffer to display in decimal?
I am receiving 2 bytes of data into a buffer-
And then displaying it using this-
They are stored as hex values and will print that way but I need to see them in decimal form. For example let's say I have 01 2C hex stored in the buffer which is the equivalent of 300 decimal. Using term.hex I get 012C displayed on the terminal.
But if I use term.dec I get 144 which is the 01 converted to 1 and the 2C converted to 44. How do I put the 012C together so it converts to 300?
Thanks.
Don
Edit: changed to solved.
cdinx := 2
chksum := $03
repeat
s := receive.rx_time(10)
if (s & $1_00)
chksum &= $0_FF
p := 1
pollack
quit
else
p := 0
chksum += s
buffer1[cdinx] := s
cdinx += 1
And then displaying it using this-
vmc.CdBeginSesX(@buffer1)
term.str(string("Credit: "))
term.hex(buffer3[2], 2)
term.hex(buffer3[3], 2)
They are stored as hex values and will print that way but I need to see them in decimal form. For example let's say I have 01 2C hex stored in the buffer which is the equivalent of 300 decimal. Using term.hex I get 012C displayed on the terminal.
But if I use term.dec I get 144 which is the 01 converted to 1 and the 2C converted to 44. How do I put the 012C together so it converts to 300?
Thanks.
Don
Edit: changed to solved.

Comments
My calculator says this
0x1*256+0x2C = 300
ie simply multiply the high byte by 256 and add to the lower byte.
term.str(string("Credit: ")) credit := (buffer1[2]) * 256 credit += (buffer1[3]) term.dec(credit)Is this the proper way? I defined credit as a long.
Thanks.
Don
DAT org buff byte 0[2]BTW, Mike G, you got your two and zero switched around. I assume you want two bytes of zeros and zero bytes of twos.
You don't need the parentheses and you can write it on one line:
Because a byte has 8 bits you can also shift the high byte by 8 (it's the same as * 256, but faster):
Andy
Andy- Thanks for those tips!