Convert Hex to Decimal???


+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006
    Posts
    5

    Default Convert Hex to Decimal???

    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.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    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
    Last edited by mister_e; - 9th May 2006 at 01:51.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Apr 2006
    Posts
    5

    Default mmmm, the problem is...

    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.

Similar Threads

  1. How to convert binary to decimal?
    By Cabomba in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th October 2007, 01:27
  2. How to convert HEX Value as formatted BIN String ?
    By Robson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th August 2007, 02:16
  3. Convert Hex to Decimal
    By RONKON in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 9th May 2006, 01:01
  4. Reading a Hex value from a Modem and showing it as Decimal..
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th March 2005, 17:58
  5. Convert a word variable to decimal
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th December 2004, 20:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts