Binary data is a position-counting method with a power of 2 at the bottom, every 2 into 1.
1. Binary and Decimal Interchange: (1) Binary decimal method: "Expand by Weight" example: (1011.01) 2 = (1x2^3+0x2^2+1x2^1+1x2^0+0x2^ ( -1) +1x2^ (-2)) 10 = (8+0+2+1 +0+0.25) 10 = (11.25) 10 rule: The number of digits on a single digit is 0, the number of digits on the 10 digits is 1, ..., sequentially increments, and the number of digits is-1, the number of digits on percentile is-2, ..., descending in descending order. Note: Not every decimal decimal can be converted into a finite bit binary number. (2) Decimal conversion to binary system · Decimal integer to binary number: "Divided by 2, in reverse order" (except the two-way) Example: (89) 10 = (1011001) 2 89÷2 ... 1 44÷2 ... 0 22÷2 ... 0 11÷2 ... 1 5÷2 ... 1 2÷2 ... 0 1 · Decimal decimal to binary number: "Times 2 rounding, sequential arrangement" (by 2 rounding Method) Example: (0. 625) 10 = (0. 2 0.625x2=1.25 ..... 1 0.25 x2=0.50 ... 0 0.50 x2=1.00 ... 1
2. Octal and binary conversions:Binary number converted to octal number: Starting from the decimal point, the integer part to the left, the fractional part to the right, each 3-bit for a group with a octal number of digits, less than 3 to use "0" to make up 3 digits, get a octal number. The octal number converts to binary number: Converts each octal number to a 3-bit binary number, and gets a binary number. Octal numbers correspond to binary numbers as follows:-> 0-> 4 001-> 1-> 5 010-> 2-> 6 011 3-> 7 cases: Convert the octal 37.416 to binary number: 3 7. 4 1 6 011 111. 100 001 110 namely: (37.416) 8 = (11111.10000111) 2 Example: Converts the binary 10110.0011 to octal: 0 1 0 1 1, 0. 0 0 1 1 0 0 2 6. 1 4 namely: (10110.011) 2 = (26.14) 83. Hexadecimal vs. binary conversions:Converts binary numbers to hexadecimal numbers: Starting with the decimal point, the integer part to the left, the fractional part to the right, each 4-bit for a group with a hexadecimal number of digits, less than 4 bits to use "0" to complement 4 bits, a hexadecimal number. Converts a hexadecimal number to a binary number: Converts each hexadecimal number to a 4-bit binary number, and a binary number is obtained. hexadecimal digits correspond to binary numbers as follows: 0000-> 0 0100-> 4 1000-> 8 1100-> C 0001-> 1 0101-> 5 1001-> 9 1101- > D 0010-> 2 0110-> 6 1010-> A 1110-> E 0011-> 3 0111-> 7 1011-> B 1111-> F Example: 16 The number of 5df.9 converts into binary: 5 D F. 9 0101 1101 1111. 1001 namely: (5DF.9) 16 = (10111011111.1001) 2 example: Convert binary number 1100001.111 to 16:0110 0001. 1110 6 1. E is: (1100001.111) 2 = (61. E) 16
original code, inverse code, complement
Assuming that there is an int type of number with a value of 5, then we know that it is represented on the computer as:
00000000 00000000 00000000 00000101
5 conversion to binary is 101, but the number of int type occupies 4 bytes (32 bits), so a heap of 0 is filled in front.
Now you want to know how-5 is represented in the computer.
In a computer, a negative number is expressed in the complement form of its positive value.
What is the complement? This has to start with the original code, the inverse code.
Original code: An integer that is converted into binary numbers according to the absolute size, called the original code.
For example 00000000 00000000 00000000 00000101 is the original code of 5.
Inverse code: The binary number is reversed by a bit, and the new binary number is called the inverse code of the original binary number.
The reverse operation refers to: the original 1, 0; originally 0, 1. (1 change 0; 0 Change 1)
For example: The 00000000 00000000 00000000 00000101 per digit is reversed, 11111111 11111111, 11111111 11111010.
said: 11111111 11111111 11111111 11111010 is a 00000000 00000000 00000000-00000101 inverse code.
The inverse code is mutual, so it can also be called:
11111111 11111111 11111111 11111010 and 00000000 00000000 00000000 00000101 are reciprocal codes.
Complement: The inverse code plus 1 is called the complement.
In other words, to get a number of the complement, first get the inverse code, and then the inverse code plus 1, the resulting number is called the complement.
For example: 00000000 00000000 00000000 00000101 of the counter code is: 11111111 11111111 11111111 11111010.
So, the complement is:
11111111 11111111 11111111 11111010 1 = 11111111 11111111 11111111 11111011
So,-5 is expressed in the computer as: 11111111 11111111 11111111 11111011. Convert to 16:0xFFFFFFFB.
To take another example, let's look at how the integer 1 is represented in the computer.
Suppose this is also an int type, then:
1, first take 1 of the original code: 00000000 00000000 00000000 00000001
2, the Counter code: 11111111 11111111 11111111 11111110
3, have the complement: 11111111 11111111 11111111 11111111
The original code of a positive number, the complement, the inverse code are the same, all equal to its own
The complement of negative numbers is: sign bit is 1, the rest of you to reverse, the bottom plus 1
The counter code is: The sign bit is 1, the others seek the opposite, but the bottom does not add 1
In other words, the inverse code plus 1 is the complement
1100110011 Original
1011001100 reverse symbol bit, bitwise counter
1011001101 to remove the symbol bit, and then add 1 to the counter
The original inverse of a positive number is the same
In a computer, data is stored in the form of a complement:
In n-bit machines, the highest bit is the sign bit, which is zero for positive and 1 for negative;
The rest of the n-1 bits are numeric digits, and you can have a value of 0 or 1.
The real value is positive: The original code, the inverse code, the complement value is exactly the same;
When the true value is negative: the numeric digits of the original code remain intact,
The numeric bit of the inverse code is the value of the original code.
The complement is the lowest digit of the inverse code plus one.
Note that the sign bit is unchanged.
For example: If the number of machines is 16 bits:
Decimal number 17 of the original code, the inverse code and complement are: 0000000000010001
Decimal number-17 of the original code, the inverse code and complement are: 1000000000010001, 1111111111101110, 1111111111101111
Decimal negative to octal or hexadecimal, just convert the decimal to binary, and then to the appropriate.