Expression of Octal numbers in C/C ++

Source: Internet
Author: User
C/C ++ Expression of the octal number in

1Expression of the. octal number

C/C ++How does one express an octal number in a language? If the number is876,We can conclude that it is not an octal number, because it is impossible to generate7The Arabic numerals above. But if the number is123Yes567, Or12345670Is it octal or10The number of hexadecimal values is possible.

So, C/C ++Rules,If you want to specify that a number uses an octal value, you must add0Such:123It is in decimal format,0123It indicates that octal is used. This is where the number of octal nodes isC,C ++.

BecauseCAndC ++No way to express the binary numberSo we learned the octal chart here,C,C ++The second method of expressing the value of a language.

Now, for the same number, for example100InCodeCommon10Hexadecimal representation, for example, during variable initialization:

Int A = 100;

We can also write:

Int A = 0144; // 0144It's octal.100; One10How to convert hexadecimal numbers8In hexadecimal notation, we will learn later.

Remember, when expressed in octal,You cannot lose the first one.0. Otherwise, the computer will communicate10Base. However, when the number of octal nodes is used, the addition cannot be used.0That is the "Escape Character" expression we learned before for expressing characters.

2 . Use of Octal numbers in escape characters

We have learned to use an escape character'/'Add a special letter to indicate a character, for example:'/N'Line feed(Line), And'/T'IndicatesTabCharacter,'/''Single quotes. Today, we learned another method to use escape characters: escape characters'/'Followed by an octal number, used to representASCIIThe character whose code is equal to the value.

For example, checkASCIICode table, We find the question mark character (?)OfASCIIThe value is63So we can convert it to an octal value:77And then use'/77'To indicate'? '. Because it is octal, it should be written'/077'But becauseC/C ++Slash addition is not allowed.10In hexadecimal notation0You can leave it empty.

In fact, we seldom use escape characters and Octal numbers to represent a character in actual programming. However, we need to know it later.

Related Article

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.