Results 1 to 3 of 3

Thread: converting the value from hexadecimal to decimal value

  1. #1
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question converting the value from hexadecimal to decimal value

    Hi to all,

    i recieved hexadecimal value through the serialport,and i read that value and assingned to string like this,
    QString str;

    str=fields[0]; //(hex value like this '0F12')

    now i want to convert this hexavalue to decimal value and that should be display on the line edit.

    please assist me to overcome this,

    thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: converting the value from hexadecimal to decimal value

    Hi,

    You have to transform the Hex code to binary (make packs of 4 bits):
    0F12 = 0000 1111 0001 0010
    0 F 1 2

    Then, you have a binary number that can be interpreted as decimal using base2:

    0*2^15+0*2^14+0*2^13+0*2^12+1*2^11+1*2^10+1*2^9+1* 2^8+0*2^7+0*2^6+0* 2^5+1*2^4+0*2^3+0*2^2+1*2^1+0*2^0 = 3858

    The bit X is multiplied by 2^(position of the bit)
    Òscar Llarch i Galán

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: converting the value from hexadecimal to decimal value


    Both take base as parameter.
    J-P Nurmi

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.