PDA

View Full Version : Convert Hex to Decimal???



RONKON
- 9th May 2006, 02:03
Hello, i have a problem

sorry for my english, i dont speak, ok

i'm using 16F876 and serial comunication, I wait for a string of bytes, my command is:

SERIN2, RX,Baud,100,NEXT,[WAIT(INICAD),STR DATAS\SIZE\ENDCAD]
I=0
Y=1
IF DATAS[I]=COMMAND THEN
While I<= DATAS[Y]
.
.
.
I=I+1
WEND
ENDIF

where:
Baud=84 NEXT=NEXT LAbel INICAD=$AA SIZE=20 ENDCAD=$FF
COMMAND=$BB

if datas[y]=1,2,3,4,5,6,7,8 or 9 it works perfectly, but datas[y]=10 or more dont's function correctly, why???

i need convert Hex to decimal??? How?

Thanks.
Dave
Mexico City.

mister_e
- 9th May 2006, 02:48
From what i understand, when you send an string of decimal character, you send each and every ASCII character of them, one after the other.

When you receive them, and use STR modifier as...
HSERIN [STR ArrayVar\4]

The results will be stor in the array variable like
ArrayVar[0]=1
ArrayVar[1]=2
ArrayVar[2]=3
ArrayVar[3]=4

So maybe...
Var1=(ArrayVar[0]*10)+ArrayVar[1]
Var2=(ArrayVar[2]*10)+ArrayVar[3]

At the end... Var1=12, Var2=34.

There's many way to do that, but it always depend how the data i sent too...
if you send 1234 and use something like

HSERIN [DEC2 Var1, DEC2 Var2]

Var1=12
Var2=34

RONKON
- 9th May 2006, 03:14
the problem is that the values come in hex and i need used SERIN2 in order to compare start and end of string, i belive that problem is the compara in the WHILE

While I<=DATAS[y]



"I" never take the value of DATAS[y] because value is A hex.

there is no a way to turn hex to decimal without using DEC

i see in a forum that convert hex to decimal something thus.

X=X-$20 or X=X-$30

i dont remember but is something thus

other idea????

i need, i'm crazy.

Thanks
Dave
Mexico City.