Converting ASCII HEX digits to decimal...


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Converting ASCII HEX digits to decimal...

    My project recieves an ASCII text string such as "3FE35853" and stores them in an array. I need to convert each ASCII byte in the array to its decimal equivalent.

    example:
    "3" = 3
    "F" = 15
    "E" = 14

    Is there an easy way to do this without using a lookup table?


    Thanks,

    John

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980


    Did you find this post helpful? Yes | No

    Default Re: Converting ASCII HEX digits to decimal...

    Are you sure it is not pairs like '3F', 'E3','58','53'?

    If it is the you can use HEX modifier.

    e.g. HSERIN [hex2 byte1, hex2 byte2, hex2 byte3, hex2 byte4]

    Ioannis

  3. #3
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Default Re: Converting ASCII HEX digits to decimal...

    Or this might be one option and you can make it easily scalable beyond 8 bit input string...
    Code:
    Hex_input       var byte
    ASCII_Array     VAR BYTE [8]
    i               var byte
    
    for i = 0 to 7
        DEBUGIN [HEX1 Hex_input]
        ASCII_Dec_Array[i] = Hex_input
    next i

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Converting ASCII HEX digits to decimal...

    Thank you. That will work.

    John

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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