Hex converting


Closed Thread
Results 1 to 10 of 10

Thread: Hex converting

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Talking

    Thanks

    This is how I hot it working, you were right about the A being 65
    Code:
    HEXConvert:
    IF DATAA = 65 THEN
    	DATAA = 10
    	RETURN
    ENDIF
    IF DATAA = 66 THEN
    	DATAA = 11
    	RETURN
    ENDIF
    IF DATAA = 67 THEN
    	DATAA = 12
    	RETURN
    ENDIF
    IF DATAA = 68 THEN
    	DATAA = 13
    	RETURN
    ENDIF
    IF DATAA = 69 THEN
    	DATAA = 14
    	RETURN
    ENDIF
    IF DATAA = 70 THEN
    	DATAA = 15
    	RETURN
    else
    	DATAA = DATAA - 48
    ENDIF
    
    RETURN

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Hmm, some people still like spaggeti much more!

    Hope at least there is a good salsa with it...

    Ioannis

  3. #3
    Join Date
    Apr 2009
    Location
    Pittsburgh, PA
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Better code

    If you're sure your data really just consists of the digits and letters A through F, use this instead. Including comments will help when you come back to it later too.

    Code:
    ' This works because 0 - 9 have decimal codes 48 - 57 and A - F have 
    ' decimal codes 65 - 70 in ASCII
    HEXConvert:
    IF DATAA >= 65 THEN
    	DATAA = DATAA - 55 ' 65 - 55 = 10, 66 - 55 = 11 etc
    else
    	DATAA = DATAA - 48 ' 48 - 48 = 0, 49 - 48 = 2 etc
    ENDIF
    
    RETURN
    http://www.asciitable.com/.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Thank you tried the new code and works like a charm

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    eg. 07D9 is what i am getting it must become a year number 2009
    An algoritm to convert Hex to Dec is as follows:

    Hex 07D9 = 9x16^0 + 13x16^1 + 7x16^2 + 0x16^3 = Dec 2009

    I don't see how you achieve the convertion with your system!

    Al.
    Last edited by aratti; - 26th June 2009 at 00:18.
    All progress began with an idea

  6. #6
    Join Date
    Apr 2009
    Location
    Pittsburgh, PA
    Posts
    17


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post
    An algoritm to convert Hex to Dec is as follows:

    Hex 07D9 = 9x16^0 + 13x16^1 + 7x16^2 + 0x16^3 = Dec 2009

    I don't see how you achieve the convertion with your system!

    Al.
    I'm sure he's using the partial algorithm he gave to get the 13 from the D for example and then plugging it into another equation like yours.

  7. #7
    Join Date
    Apr 2009
    Location
    Pittsburgh, PA
    Posts
    17


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by ukemigrant View Post
    If you're sure your data really just consists of the digits and letters A through F, use this instead. Including comments will help when you come back to it later too.

    Code:
    ' This works because 0 - 9 have decimal codes 48 - 57 and A - F have 
    ' decimal codes 65 - 70 in ASCII
    HEXConvert:
    IF DATAA >= 65 THEN
    	DATAA = DATAA - 55 ' 65 - 55 = 10, 66 - 55 = 11 etc
    else
    	DATAA = DATAA - 48 ' 48 - 48 = 0, 49 - 48 = 2 etc
    ENDIF
    
    RETURN
    http://www.asciitable.com/.
    Of course 49 - 48 <> 2 . Luckily it was in the comments but still...

Similar Threads

  1. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  2. Converting Dec word to Hex string
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th August 2007, 05:44
  3. Need help converting to ASCII Hex format
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th August 2007, 19:14
  4. Converting ASCII to HEX
    By BobP in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th September 2006, 10:21
  5. Converting Bytes from hex to Dec
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th April 2005, 19:44

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