● positive decimal to binary
Split method, the decimal integer split into a number of binary weights and weight, if the weight is below a write, write 0 otherwise. Such as:
34 = 32 + 2
128 64 32 16 8 4 2 1
0 0 1 0 0 0 1 0 => 0010 0010
● positive binary conversion to decimal
Weighting method, so that each number is multiplied by the current binary bit heavy weights, and then all took the opportunity to add up to. Such as:
0010 0010 => 0*27 + 0*26 + 1*25 + 0*24 + 0*23 + 0*22 + 1*21 + 0*20
=> 0 + 0 + 32 + 0 + 0 + 0 + 2 + 0
=> 34
● negative decimal to binary
The absolute value of the negative decimal integer converted to binary, and then bitwise plus 1. Such as:
-34 converted to a binary outcome:
34 is converted to binary: 0010 0010
Bitwise: 1101 1101
Coupled with a: 11,011,110
● negative binary to decimal
Save a first bit inverse press, and then combined using weighting as a decimal integer, a negative sign is added last. Such as:
11011110 converted to decimal:
First minus one: 1101 1101
Bitwise: 0010 0010
The combined decimal integer: 34
Finally, add a negative sign: -34