(2, 8, 10, 16) The story behind the conversion between the binary

Source: Internet
Author: User

Today, when it comes to the question of string conversion to int, the conversion problem of signed number, we find that we need to look back into the problem of the system. Find some information, think can also, borrow a paragraph here and prepare to check.

16 binary: Use 16 as the base counting system. 10 to 15 are represented by the number 0-9 and the letter a-f (or its uppercase a-f).
Hexadecimal number converted to decimal number
2 binary, with two Arabic numerals: 0, 1;
8 binary, with eight Arabic numerals: 0, 1, 2, 3, 4, 5, 6, 7;
10 binary, with 10 Arabic numerals: 0 to 9;
16 binary, with 16 Arabic numerals ... Wait, the Arabs, or Indians, invented only 10 numbers?
16 binary is every 16 into 1, but we only 0~9 these 10 numbers, so we use a,b,c,d,e,f these six letters to represent 10,11,12,13,14,15. Letters are case insensitive.
The No. 0 digit of the hexadecimal number has a weight of 16 0, the 1th bit has a weight of 16 1, and the 2nd digit is 16 2.
So, on the nth (n from 0) bit, if it is a number x (X is greater than or equal to 0, and X is less than or equal to 15, that is: F), the size represents the n-th square of x * 16.
...........................................................
The number of N can be 0---(N-1) for more than 9 letters A-F
For example:
10 binary 32 is represented as 16 binary is: 20
16 binary 32 is represented as 10 binary is: 3x16^1+2x16^0=50
6.1 Why do I need octal and hex?
In programming, we are still used to 10 binary ... After all, C + + is a high-level language.
Like what:
int a = 100,B = 99;
However, because the data is represented in the computer and eventually in binary form, sometimes binary is used to solve the problem more intuitively.
However, the binary number is too long. For example, an int type occupies 4 bytes and 32 bits. For example, 100, a binary number expressed in int type would be:
0000 0000 0000 0000 0110 0100
Faced with such a long number of thinking or operation, no one would like it. Therefore, c,c++ does not provide a way to write binary numbers directly in the code.
This problem can be solved with 16 or 8 binary. Because, the larger the system, the shorter the length of the expression. But why is the 16 or 8 binary, and not the other, such as 9 or 20 binary?
2, 8, 16, respectively, 2 1 times, 3 times, 4 parties. This makes it possible to convert very directly between the three kinds of binary. The binary number is shortened by 8 binary or 16 binary, but the expression of binary number is maintained. You can find this in the following lessons about the conversion.

(2, 8, 10, 16) The story behind the conversion between the binary

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.