Results 1 to 2 of 2

Thread: Decimal to Binary conversion

  1. #1
    Join Date
    Oct 2014
    Posts
    71
    Thanks
    13
    Qt products
    Qt5
    Platforms
    Windows

    Question Decimal to Binary conversion

    Hello All,

    In my code I have to convert a decimal number into binary by using some QT inbuilt function.
    I am having a decimal in array like below
    Qt Code:
    1. unsigned int Data_ecu2uss[12];
    2. Data_ecu2uss[0] = 68159
    3. Data_ecu2uss[1] = 3554148352
    4. ....
    5. ...
    6. Data_ecu2uss[12] = 3554148395
    To copy to clipboard, switch view to plain text mode 

    I am trying to convert like below but getting always ival as 0
    Qt Code:
    1. QString Hexnumber = QString::number(Data_ecu2uss[0],16);
    2. int ival = Hexnumber.toInt(0,2);
    3. qDebug()<<"ival"<<ival;
    4. ui->le_ecu2uss_data1->setText(QString::number(ival,2));
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Decimal to Binary conversion

    A number is a number, you don't need any conversions.

    Qt Code:
    1. i->le_ecu2uss_data1->setText(QString::number(Data_ecus2uss[0], 2));
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    anh5kor (6th February 2015)

Similar Threads

  1. Binary files and conversion
    By timmu in forum Qt Programming
    Replies: 27
    Last Post: 11th December 2012, 11:19
  2. decimal display in QDoubleSpinBox
    By henryjoye in forum Qt Programming
    Replies: 0
    Last Post: 20th December 2011, 23:37
  3. modifications of decimal separator
    By 21did21 in forum Qwt
    Replies: 2
    Last Post: 2nd August 2011, 21:41
  4. Formatting for two decimal places
    By TomJoad in forum Newbie
    Replies: 1
    Last Post: 4th April 2011, 16:56
  5. QTableWidget and Decimal places
    By pshah.mumbai in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2008, 08:30

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.