Hex values to decimal


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103

    Default Hex values to decimal

    Hello everyone ..

    We've got a pic based system that doesn't have an lcd and also which stores some values into EEPROM .. When we are done with collecting the datas into eeprom , we remove the PIC and mount it to the PICKIT3 and export the hex file in order to read the stored EEPROM values on specific addresses on PICKIT3 standalone GUI ... The datas we store into the eeprom are 16 bit values and we use the address $00 to store the lowbyte of the value and $01 for the highbyte ...

    Is there a possible way to view this 16 bit data stored in the eeprom in decimal format instead of HEX format ? We need this because each time the user who obtains the datas needs to use a hex to dec converter software to interpret the values and that number converting stuff takes a long time for him ..

    I hope I made my point clear ...

    Thanks in advance ...
    - Ipsa scientia potestas est -

  2. #2
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    Output the data serially on the UART or bit bang it out of a pin?

    Why involve a pickit3 at all, for just reading the stored data?

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    a small board sending data to the PC " Hyperterminal " .... when the chip is placed on a ZIF socket ??? ( see "Debug" PBP command i.e. )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    Is there an another way to make it work ? Such as viewing the hex on EXCEL ? or an another software ?
    - Ipsa scientia potestas est -

  5. #5
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    Have to agree with the others, use serial and either cable or use a HC-05 bluetooth module and read the values or HEX stored via a terminal application, or write your own app using something like VB or Liberty Basic.

    You risk damage to the PIC constantly removing it and then re-inserting it into your PCB

  6. #6
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    Of course you can do the conversions in Excel; but again, how would you get the data into Excel in the first place? And if you do that, (using something like StampDaq or some such), then why not let the pic/PBP itself do the conversion(s)?

  7. #7
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    Ok thanks to everyone for the answers ..
    - Ipsa scientia potestas est -

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    Hi All,
    How to convert a HEX value to DEC value. For example: Var mai = $2B and I want to store the decimal value of this (which is 43 in decimal) in other variable.
    On LCD is all ok, shows the right dec value, but how to store this in decimal in other variable that's my problem.
    I do some search on the forum but no success. Can me to someone explain how to do?

    Thanks.

    Code:
    #CONFIG
    cfg = _INTRC_OSC_NOCLKOUT
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
     __CONFIG cfg
    #ENDCONFIG
    
    DEFINE OSC 8      ; Use a 8 MHZ internal clock 
    OSCCON = %01110000
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_BAUD 38400
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    Define LCD_DREG PORTC
    Define LCD_DBIT 0
    Define LCD_RSREG PORTC
    define LCD_RSBIT 4
    define LCD_EREG PORTC 
    define LCD_EBIT 5 
    define LCD_BITS 4
    define LCD_LINES 2
    define LCD_COMMANDUS 2000
    define LCD_DATAUS 50
    
    ANSELH = 0        ; Set RB6 (TX) pin to digital
    ANSEL = 0         ; Set all digital
    TRISA = %011100   ; Set RA5,RA4,RA3 input ; RA2,RA1,RA0 output
    TRISB = %0011     ; Set RB4,RB5 input ; RB6,RB7 output
    TRISC = %00000000 ; Set RC0,RC3,RC4,RC5,RC6, RC1,RC2,RC7 output
    CM1CON0 = 0       ; Disable comparator 1
    CM2CON0 = 0       ; Disable comparator 2
    OPTION_REG.7=1   ; Disable weak pull ups
    
    mai var byte[2]
    decvalue var byte
    Lcdout $fe, 1
    pause 1000
    
    main:
    hserout ["01 05",13,10]
    pauseus 1                   
    HSerin 1000,main, [wait ("41 05"), skip 1, hex mai]  
     
    Lcdout $fe, 1
    lcdout  dec mai
    
    let decvalue = mai 
    
    pause 1000
    
    goto main
    Last edited by louislouis; - 2nd January 2017 at 21:07.

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    to start with
    mai var byte[2]
    HSerin 1000,main, [wait ("41 05"), skip 1, hex mai]
    probably does not work as you intend

    input
    41 05xC , mai[0]=$C or 12 or %00001100
    41 05x2C , mai[0]=$2C or 44 or %00101100
    41 05x42C , mai[0]=$2C or 44 or %00101100
    41 05x552C , mai[0]=$2C or 44 or %00101100
    41 05x3FED2C , mai[0]=$2C or 44 or %00101100
    mai[1] takes no part in this

    secondly
    the data is always binary once "parsed" by the HEX modifier in hserin ,it just depends on how you display/interpret the data
    Warning I'm not a teacher

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    Quote Originally Posted by richard View Post
    to start with


    probably does not work as you intend

    input
    41 05xC , mai[0]=$C or 12 or %00001100
    41 05x2C , mai[0]=$2C or 44 or %00101100
    41 05x42C , mai[0]=$2C or 44 or %00101100
    41 05x552C , mai[0]=$2C or 44 or %00101100
    41 05x3FED2C , mai[0]=$2C or 44 or %00101100
    mai[1] takes no part in this

    secondly
    the data is always binary once "parsed" by the HEX modifier in hserin ,it just depends on how you display/interpret the data
    Thanks Richard for answer, but still not clear for me. The serin input data is a string like:
    41 05 2B The "41 05" part represent the identificator and the "2B" is the value in hex which is changing and this part I want store in variable in dec format.

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    You don't get to choose in what format the number is stored, it doesn't work like that.
    2B in hex
    43 in decimal
    00101011 in binary
    + in ASCII
    These are all the same thing and stored exactly the same in a variable.
    Code:
    mai = $2B
    mai = %00101011
    mai = 43
    mai = "+"
    Exactly the same result. It's just how we choose to interpret the information.

    If you want to receive a number expressed in a "human readable" format (ie represented as an ASCII string) you use the available DEC/HEX/BIN modifiers (as you are).

    The code, as it runs, will then interpret ASCII characters and convert to an actual number so that the ASCII string '2B' becomes the decimal value 43. There's no need to use an array in the HSERIN statement because you're not storing the '2' and the 'B', you're storing the decimal value 43 that the ASCII string '2B' represents.

    Then, when you do the LCDOUT you, again, use the DEC (or HEX or BIN) modifier to convert the decimal value 43 back into the ASCII characters '4' and '3' which are displayed on the LCD.

    Since your LCD shows 43 when you send '41 05 2B' everything is working exactly as expected and when you do decvalue = mai you'll copy the content of mai to decvalue so it TOO contains 43.

    I don't get what the problem is......

    /Henrik.

  12. #12


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    Quote Originally Posted by HenrikOlsson View Post
    You don't get to choose in what format the number is stored, it doesn't work like that.
    2B in hex
    43 in decimal
    00101011 in binary
    + in ASCII
    These are all the same thing and stored exactly the same in a variable.
    Code:
    mai = $2B
    mai = %00101011
    mai = 43
    mai = "+"
    Exactly the same result. It's just how we choose to interpret the information.

    If you want to receive a number expressed in a "human readable" format (ie represented as an ASCII string) you use the available DEC/HEX/BIN modifiers (as you are).

    The code, as it runs, will then interpret ASCII characters and convert to an actual number so that the ASCII string '2B' becomes the decimal value 43. There's no need to use an array in the HSERIN statement because you're not storing the '2' and the 'B', you're storing the decimal value 43 that the ASCII string '2B' represents.

    Then, when you do the LCDOUT you, again, use the DEC (or HEX or BIN) modifier to convert the decimal value 43 back into the ASCII characters '4' and '3' which are displayed on the LCD.

    Since your LCD shows 43 when you send '41 05 2B' everything is working exactly as expected and when you do decvalue = mai you'll copy the content of mai to decvalue so it TOO contains 43.

    I don't get what the problem is......

    /Henrik.
    Hi Henrik, yes right the LCD shows the value in dec that is what I want, but next in the code I want to do some math or comparsion with decimal value of this number.

  13. #13
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    And what's stopping you?
    Either I don't get it or you don't :-) No offense.

    Code:
    mai VAR BYTE
    value VAR BYTE
    
    mai = $2B   'assign value to variable, in this case the value 43 represented as HEX.
    
    mai = mai + 10
    LCDOUT $FE, 1, DEC mai   ' will show 53
    PAUSE 2000
    
    value = mai * 4
    LCDOUT $FE, 1, DEC value   ' will show 212
    PAUSE 2000
    
    value = value / 5
    LCDOUT $FE, 1, DEC value    ' will show 42
    PAUSE 2000
    
    IF mai < $3A THEN
      LCDOUT $FE, 1, "mai is smaller than 58"
    ENDIF
    PAUSE 2000
    
    IF mai > value THEN
      LCDOUT $FE, 1, "Yes, mai is bigger than value"
    ENDIF
    PAUSE 2000
    
    LCDOUT $FE, 1, DEC mai, "  ", HEX mai
    PAUSE 2000
    Show us the math or comparison you're wanting to do and tell us wha the problem you're having actually is.

    /Henrik.
    Last edited by HenrikOlsson; - 3rd January 2017 at 20:53.

  14. #14


    Did you find this post helpful? Yes | No

    Default Re: Hex values to decimal

    ahaaa, I thought that in PBP not work and I don't try this all the time. Now it's
    more clear. Thanks guys for the patience with me, I'm just an old beginner (63) and I try to learn about these (new for me) things.

Similar Threads

  1. Hex to Decimal to Binary
    By Ramius in forum FAQ - Frequently Asked Questions
    Replies: 3
    Last Post: - 28th March 2014, 02:01
  2. Decimal PWM Cycle values?
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th April 2012, 13:58
  3. Hex to Ascii to Decimal
    By khoog in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st July 2009, 06:27
  4. Convert Hex to Decimal
    By RONKON in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 9th May 2006, 02:01
  5. Decimal values from string
    By GioppY in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th November 2005, 22:10

Members who have read this thread : 1

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