String 10 binary, 10 binary to string, and 16 binary number display

Source: Internet
Author: User
Tags locale
        Id=dateline->text ();//Get string
        QString str = ID;
        BOOL OK;
        int hex = Str.toint (&ok, +);       Turns a string into a 16-mechanism number
        hex=hex+1;
        QString t = qstring::number (hex, +). ToUpper (); Turns a number into a 16 mechanism and displays it in uppercase
        Dateline->settext (t); shown in Textveiw ()
        cout<< hex<<endl;
    
16 binary conversion.
This is a very classic code, mainly used in string and int type conversion.
Implementation features:
1, the string according to 16 decimal number, self-increment, only with the modification
   int hex = Str.toint (&ok, 10);
  hex=hex+1;

2, the string in accordance with the 10 binary number, self-increment
   int hex = Str.toint (&ok, 16);
  hex=hex+1;
3. Convert the string to 16, and then display it as a 10 binary number.
int hex = Str.toint (&ok, 16);   
  QString t = qstring::number (hex, ten). ToUpper ();
4. Convert the string to 10 decimal and then display it in 16 digits
int hex = Str.toint (&ok, 10);   
  QString t = qstring::number (hex, +). ToUpper ();

Principle:
int Qstring::toint (BOOL * OK = 0, int base = ten) const
Returns the string converted (convert) to a int using base base, which is ten by default and must be between 2 and 36 (conversion binary, only 2 To 36, binary, 10 binary, 9 binary, etc. can be converted), or 0. Returns 0 if the conversion fails.

If A conversion error occurs, *ok is set to false; Otherwise *ok is set to true.
The conversion succeeds, the return value is OK is 1, return error, the value is 1. You can also use the OK value to determine whether the conversion was successful.

If base is 0, the C language Convention are used:if the string begins with "0x" and base is used; If the string begin S with "0", base 8 is used; Otherwise, base is used.

The string conversion would always be happen in the ' C ' locale. For locale dependent conversion use Qlocale::toint ()



Yearline->settext (Qstring::number (cmd.trimmed () ToInt (), 10)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.