Note: This content reference and Preach Wisdom podcast Java content explanation, of course, I tidied up a bit, make a record ~ ~ ~ which I think is very valuable is the symbolic data representation, really go deep understanding computer, although I am a slag slag ~ ~ ~
The so-called system refers to: is a bit into the system, is a method of carrying out the people. For any kind of binary--x, it means that the number operation at a certain position is every x in a bit. Binary is every two in one, eight into the system is every eight into a, decimal is every ten into a, hexadecimal is every 16 into one.
A common conversion of the binary
1. Provides four representations of integer constants in Java
(1) binary consists of 0, 1. Start with 0b.
(2) octal by 0, 1, ... 7 composition. Start with 0.
(3) Decimal by 0, 1, ... 9 composition. Integers are decimal by default.
(4) hexadecimal by 0, 1, ... 9,a,b,c,d,e,f (both uppercase and lowercase) are composed. Start with 0x.
2. Binary conversion
(1) Other decimal (coefficient * Radix ^ right)
Coefficient: is the value on each bit
Cardinality: X-binary cardinality is X
Right: The data on each digit, from the right, and numbering starting from 0, the corresponding number is the right to the data.
Example:
0B10101 (this number is a binary number, because it starts with 0b)
=1*2^4 + 1*2^2 + 1*2^0
=16 + 4 + 1
=21
0123 (this number is a number of octal, because it starts with 0)
=1*8^2 + 2*8^1 + 3*8^0
=64 + 16 + 3
=83
0X3C (this number is a hexadecimal number, because it starts with 0x)
=3*16^1 + c*16^0
=48 + 12
=60
(2) Decimal to other binary conversions
In addition to the base fetch, the remainder is reversed until the quotient is 0.
Example:
52 respectively get binary, decimal, hexadecimal
Get binary:
52/2 = 260
26/2 = 130
13/2 = 6 1
6/2 = 3 0
3/2 = 1 1
1/2 = 0 1
0b110100
Get octal:
52/8 = 64
6/8 = 0 6
064
Get 16 binary:
52/16 = 3 4
3/16 = 0 3
0x34
3. The fast conversion method of the binary conversion
(1) Conversion between decimal and binary
8421 yards.
(2) binary to octal, hexadecimal conversion
Ii. signed Data representation method
Within the computer, there are three representations of the symbolic data: The original code, the inverse code, and the complement. All data is performed in the complement.
The original code: is the binary fixed-point notation. That is, the highest bit is the sign bit, "0" means positive, "1" is negative, and the remaining bits represent the size of the value.
Anti-code: The inverse code of positive number is the same as its original code, negative number of the inverse code is to its original code bitwise negation, except the sign bit.
Complement: The complement of a positive number is the same as its original code, minus the complement is in its inverse code of the bottom plus 1.
Example:
1) It is known that a number of X's original code is 10110100B, try to find X's complement and anti-code.
Sign bit value bit
Original code: 10110100
Anti-code: 11001011
Complement: 11001100
2) A number of X's complement 11101110B is known, try to find its original code.
Sign bit value bit
Complement: 11101110
Anti-code: 11101101
Original code: 10010010
Common conversion and symbolic data representation