stay C++ In the integer constant of , Integers are divided into decimal integers 、 Octal and hexadecimal integers .

Given an integer constant, how to distinguish which system is it ?/ Give an integer constant , Such as 100, The default is decimal , If you add before the number 0, Such as 0100, Then this number is expressed as an octal number , If you add before the number 0x, Such as 0x100, Then this number is expressed as a hexadecimal number .

Use cout When you output an integer , By default, the output is in decimal system , If you want the number to be output in octal or hexadecimal , You need to use the output format controller ./ If you use format controllers , To include header files iomanip.
The decimal output format controller is dec( By default ), Octal format control is oct, The hexadecimal format controller is hex.

Here is an example of the program

// The use of different base integers 
// Give an integer constant , Such as 100, The default is decimal ,
// If you add before the number 0, Such as 0100, Then this number is expressed as an octal number
// If you add before the number 0x, Such as 0x100, Then this number is expressed as a hexadecimal number
// Use cout When you output an integer , By default, the output is in decimal system ,
// If you want the number to be output in octal or hexadecimal , You need to use the output format controller
// If you use format controllers , To include header files iomanip
// The decimal output format controller is dec, Octal format control is oct, The hexadecimal format controller is hex #include <iostream>
#include <iomanip> // Contains the output format control header file
using namespace std;
int main()
{
cout<<" The following integers are output in decimal system "<<endl;
int a; // integer a
a=; // Assign a decimal integer value to
cout<<"after a=11( Decimal system 11), a="<<a<<"( Decimal system )"<<endl;
a=; // Assign an octal integer value to
cout<<"after a=011( octal 11), a="<<a<<"( Decimal system )"<<endl;
a=0x11; // Assign an octal integer value to
cout<<"after a=0x11( Hexadecimal 11), a="<<a<<"( Decimal system )"<<endl<<endl; cout<<" The following integers are output in the decimal system specified by the output format controller "<<endl;
a=; // Assign a decimal integer value to
cout<<"after a=11( Decimal system 11), a="<<dec<<a<<"( Decimal system )"<<endl;
a=; // Assign an octal integer value to
cout<<"after a=011( octal 11), a="<<oct<<a<<"( octal )"<<endl;
a=0x11; // Assign an octal integer value to
cout<<"after a=0x11( Hexadecimal 11), a="<<hex<<a<<"( Hexadecimal )"<<endl; return ;
}

Running results

C++ More articles about different decimal integers

  1. C How to define in language that can be preserved 16 Variables of decimal integers

    Can pass int or long int Storage ,16 M-integers are integers after all ,16 M-ary is just a way of counting . for example ,int x=0x16; Hexadecimal (hexadecimal) It's just a representation of data in a computer , The rule is “ Every ten ...

  2. Javascript 16 Conversion from decimal to signed 10 Hexadecimal integer

    In the project to develop a single-chip corresponding to the data interface , You need to convert a two byte hexadecimal to -256~255 Of 10 Hexadecimal number . Baidu has no corresponding and concise tutorial for a long time , Just write one by yourself .   We all know JavaScript Integer types are ...

  3. JAVA Different base integers are defined in

    1. Octal integer with 0 start int b = 033;// Represents a decimal number 27,3 × 81 + 3 × 80 = 3 × 8 + 3 × 1 = 24 + 3 = 27 2. Hexadecimal integers are represented by 0x perhaps 0X start i ...

  4. 16 Base number ascii Code into the corresponding character , pay ipmitool Query hardware information

    I need to be in use recently ipmitool Query server hardware information .ipmitool Query hardware information Like the power supply , Use command : obtain PSU0 Information :Ipmitool raw 0x3a 0x71 0x00: obtain PSU1 Information :I ...

  5. 1813. M Base number problem

    1813. M Base number problem Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description The trial C++ Class to represent the general decimal number . Given 2 ...

  6. 【String Conversion between base type and base type 】 as well as 【 Hexadecimal conversion 】

    1. Basic data type ----> String type : Method 1 : Use to connect an empty string , for example   Basic data type +“” : Method 2 : Static methods String.valueOf(), Specific have : String.valueOf ...

  7. PAT/ Problem set of decimal conversion

    B1022. D It's binary A+B (20) Description: Input two nonnegative 10 Hexadecimal integer A and B(<=230-1), Output A+B Of D (1 < D <= 10) Hexadecimal number . Input: ...

  8. PAT 1022. D It's binary A+B (20)

    Input two nonnegative 10 Hexadecimal integer A and B(<=230-1), Output A+B Of D (1 < D <= 10) Hexadecimal number . Input format : The input is given in turn on a line 3 It's an integer A.B and D. Output format : Output A+B Of D ...

  9. 1022. D It's binary A+B (20)

    1022. D It's binary A+B (20) The time limit 100 ms Memory limit 32000 kB Code length limit 8000 B The procedure of judging questions Standard author CHEN, Yue Input two nonnegative 10 Hexadecimal integer A and ...

Random recommendation

  1. Java Deep and shallow copies of objects 、 Intersection union of sets

    http://blog.csdn.net/lian_1988/article/details/45970927 http://www.cnblogs.com/yxnchinahlj/archive/2 ...

  2. html5 Analysis of the function of geographical location

    Geolocationd The basic principle 1.GPS    GPS The basic principle is to measure the distance between the satellite with known position and the user's receiver , Then, by synthesizing the data of multiple satellites, we can know the location of the receiver . It is suitable for people with GPS Functional devices (1) advantage : stay ...

  3. AndroidStudio spot 9 Picture file error

    If the project is not only 9 The plan is wrong , There is also a bunch of illegal resources included PNG, What to do with that ??? In this case , The right solution is to find build.gradle file , stay buildToolsVersion Add the following two sentences : aaptOp ...

  4. js The element object of

    Element object (element object )        ** To operate element object , First of all, we must obtain element,                       - Use document The corresponding way to get   ...

  5. [CLR via C#]14. character 、 String and text processing

    One . character stay .NET Framewole in , The character is always expressed as 16 position Unicode Code value , This simplifies the development of internationalized applications . Each character is represented as System.Char structure ( A value type ) An example of .System ...

  6. Dll Learning one _Dll Create and dynamically reference forms and release forms Demo

    1. newly build Dll engineering 2.Dll The whole code of the project library SubMain; { Important note about DLL memory management: ShareMem must b ...

  7. SVG note

    SVG Scalable vector graphics (Scalable Vector Graphics) It's based on extensible markup language (XML), A graphic format used to describe two-dimensional vector graphics .SVG yes W3C("World Wide Web C ...

  8. python orm frame

    #!/usr/bin/python# -*- coding: utf-8 -*-from sqlalchemy import create_enginefrom sqlalchemy import T ...

  9. spark And JDBC Development ( Connect to database test )

    spark And JDBC Development ( Connect to database test ) The following operations are local mode operations : 1. stay Eclipse4.5 To build a project RDDToJDBC, And create a folder lib Used to place third-party driver packages [hadoop@CloudD ...

  10. Qt Used in C++ Knowledge and skills - What you have to understand

    If you're not sure you're using Qt What I have mastered in programming C++ Is knowledge enough , This section will help you . Here are Qt In itself and in use Qt Programming involves C++ knowledge , therefore , By reading this section , You'll know if you're missing some C++ Skill . ...