16 and the transformation of computer system

Source: Internet
Author: User

English Name: Hex number system is a representation of the data in the computer. is not the same as our daily decimal notation. It is made up of 0-9,a-f. The corresponding relationship with the 10 binary is: 0-9 corresponds to 0-9; A-f corresponds to 10-15; The number of N-ary can be expressed in 0---(N-1) for more than 9 letters A-F. The 10-in-32 representation of the 16 system is: 20 16 into the 32 into 10 is: 3x16^1+2x16^0=50 programming, we often use the 10 system. After all, C + + is a high-level language. For example: int a = 100,B = 99; However, because the data is represented in the computer and ultimately in the form of a binary, it is sometimes possible to use the binary to solve the problem more intuitively. However, the binary number is too long. For example, the int type occupies 4 bytes and 32 bits. For example, 100, using the int type binary number expression will be: 0000 0000 0000 0000 0110 0100 Face Such a long number of thinking or operation, no one will like. Therefore, c,c++ does not provide a way to write binary numbers directly in the code. This problem can be solved by using a 16-or 8-way system. Because, the larger the system, the shorter the length of the expression of the number. Why, however, is 16 or 8, and no other, such as 9 or 20 in the system. 2, 8, 16, respectively 2 of 1 times, 3 times, 4 times side. This makes it possible to convert three of different systems very directly to each other. The binary number is shortened by 8 or 16, but the expression of binary number is maintained. You can see this in the following course on conversion.II. Conversion Binary Conversion DecimalThe weight of the No. 0 digit of the binary number is 2 of 0, and the weight of the 1th digit is 2 1 times. So, there is a binary number: 101100100, converted to 10 to: 356 with a horizontal calculation 0 x2^0 + 0X 2^1 + 1X 2^2 + 0x2^3 + 0x2^4 + 1 x2^5 + 1 x2^6 + 0 X 2^7 + 1X 2^8 = 3 56 0 Times How much is 0, so we can also skip the bit with a value of 0 directly: 1X 2^2 + 1 x2^5 + 1X 2^6 + 1X 2^8 = 356 4 + + + + 256 =356Octal Conversion DecimalThe octal system is every 8 into 1. The octal number uses the 0~7 eight numbers to express a number. The No. 0 digit of the octal number is 8 0, the 1th digit is 8 1, and the 2nd digit is 8 of the 2 .... So, there is a octal number: 1507, converted to decimal: 839, the specific method is as follows: can be directly calculated by horizontal: 7 * 8^0 + 0 * 8^1 + 5 * 8^2 + 1 * 8^3 = 839 can also be expressed in vertical No. 0 7 * 8^0 = 7 1th digit 0 * 8^1 = 0 2nd digit 5 * 8^2 = 320 3rd digit 1 * 8^3 = A16 decimal in binary conversion16 is every 16 into 1, but we only 0~9 these 10 digits, so we use a,b,c,d,e,f these six letters to represent 10,11,12,13,14,15 respectively. Letters are case-insensitive. The No. 0 digit of the hexadecimal number is 16 of the 0, the 1th digit is 16 1, and the 2nd digit is 16 of 2 .... So, at 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 n-th side of X * 16 is represented. Suppose there is a 16-in-2AF5 direct calculation is: 5 * 16^0 + F * 16^1 + A * 16^2 + 2 * 16^3 = 10997 can also be expressed in vertical: No. 0:5 * 16^0 = 5 1th: F * 16^1 = 240 2 digits: A * 16^2 = 2560 3rd: 2 * 16^3 = 8192-------------------------------------10997 Now you can see that all of the conversion into 10, the key is the different weight values. Suppose someone asks you, ten to 1234 why is 1234. You can give him such a formula: 1234 = 1 * 10^3 + 2 * 10^2 + 3 * 10^1 + 4 * 10^0 Two, Hex converts to each other First we look at a binary number: 1111, how much is it? You might want to calculate this: 1 * 2^0 + 1 * 2^1 + 1 * 2^2 + 1 * 2^3 = 1 * 1 + 1 * 2 + 1 * 4 + 1 * 8 = 15. However, since 1111 is only 4 digits, we have to remember directly each of its weights, and it is from high to low,: 8, 4, 2, 1. That is, the maximum weight is 2^3 = 8, followed by 2^2 = 4,2^1=2, 2^0 = 1. Remember 8421, for any 4-bit binary number, we can quickly work out its corresponding 10 value. The following list of four-bit binary xxxx all possible values (the middle skipped part) only 4 digits of the 2-digit fast calculation method decimal value 16 Binary 1111 = 8 + 4 + 2 + 1 = =f 1110 = 8 + 4 + 2 + 0 = 14= E 1101 = 8 + 4 + 0 + 1 = 13= D 1100 = 8 + 4 + 0 + 0 = =c 1011 = 8 + 0 + 2 + 1 = 11= B 1010 = 8 + 0 + 2 + 0 = ten =a 1001 = 8 + 0 + 0 + 1 = 9 = 9 .... 0001 = 0 + 0 + 0 + 1 = 1 = 1 0000 = 0 + 0 + 0 + 0 = 0 = 2 The number to be converted to 16, that is, the 4-bit, respectively, to 16. For example (above, the corresponding hexadecimal): 1111 1101, 1010 0101, 1001 1011 F D, A 5, 9 B Conversely, when we see FD, how quickly we convert it to binary number. First convert F: see F, we need to know it is 15 (maybe you are not familiar with the five number of a~f), then 15 how to use 8421. should be 8 + 4 + 2 + 1, so four digits are all 1:1111. Then convert D to see D, know it is 13,13 how to use 8421 to gather it. should be: 8 + 4 + 1, that is: 1101. So, FD is converted to binary number, which is: 1111 1101 because hexadecimal is fairly straightforward to convert to binary, so we need to convert a decimal number to a 2-digit number, or we can convert it to a 16-system and then convert it to 2. For example, the decimal number 1234 converted into two, if you want to divide by 2, directly to get 2 of the number, you need to calculate more times. So we can divide by 16 and get the 16 binary number: the divisor calculationProcess quotient remainder 1234 1234/16 2 77/16 4 (D) 4 4/16 0 4 The result 16 is: 0X4D2 then we can write the 0x4d2 binary form directly: 0100 1101 0010. The mapping relationship is: 0100--4 1101--D 0010--2 Likewise, if a binary number is very long and we need to convert it to a 10-digit number, we can also convert the binary to a 16-in-one, and then convert it to a 10-binary system, in addition to the method we've learned before. Here is an example of a binary of type int: 01101101 11100101 10101111 00011011 We have a four-bit conversion to 16:6D E5 AF 1Bdecimal Turn hexadecimaldecomposition of the mining remainder theorem, e.g. converting 487710 into 16:

[1] 487710÷16=30481....14 (e) 30481÷16=1905....1 1905÷16=119....1 119÷16=7....7 7÷16=0....7 This will count to 487710 (=7711 )

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.