Two-level system to decimal

Convert a positive integer to binary, divide by 2 to take the remainder, and arrange in reverse order. Divide the positive decimal number by two, and divide the obtained quotient by two, and so on until the quotient is zero or one, and then list each step on the side The remainder of, and finally write it down, you can
divide 42 by 2 and the remainders are 010101 respectively, and then arrange them backwards. The binary corresponding to 42 is 101010
integer binary conversion decimal: first fill in the digits of the binary number, if the first digit is 0 means a positive integer, if the first one is a negative integer. The digits in the binary will be multiplied by the corresponding values ​​below, and then the addition will be the decimal system. For example, 1010 is converted to decimal.
If the first digit of the binary complement is 1, it needs to be reversed and converted: for example, 1110111, , The first digit is 1, then just take the opposite -00010100, and then calculate the decimal system corresponding to 10100 as 20, so the corresponding decimal system is -20

JAVA

Guess you like

Origin blog.51cto.com/14980895/2547908