Help you quickly understand the conversion of mental arithmetic from decimal to binary. If you create your own merit, you can understand it, but you won't.
Catalogue: 1. Memorize several special binary numbers. two。 Find the law of binary conversion. 3. The understanding of the rules of converting to binary. 4. Take digestion as an example, and you will understand it in one instance.
~- -
Foreword: do not understand the front, you can first look at the example.
- -
- -
One: memorize several special binary numbers.
- -
Q: why only remember these numbers? Answer: because IP addresses are represented in binary, the range is from 00000000.00000000.00000000.000000000000.00000000 to 11111111.1111111111111111111111111111111111, and 0 is 0 in both binary and decimal, while binary 11111111 is 255 in decimal, so IP addresses range from 0.0.0.0 to 255.255.255.255. The decimal binary number represents 1281000 00001921100 00002241110 002401111 00002481111 10002521111 11002541111111025511111111
- -
two。 Find the law of binary conversion.
- -
The law of decimal numbers 128128 + 2 ^ 6 (64) = 192 192 + 2 ^ 5 (32) = 224224224 + 2 ^ 4 (16) = 240240240 + 2 ^ 3 (8) = 248248248 + 2 ^ 2 (4) = 252252252 + 2 ^ 1 (2) = 254254254 + 2 ^ 0 (1) = 255255255 is the last
You will find that the difference between every two numbers is decreasing from 128Mui 225: 64-32-16-8-4-2-1. Remember this.
- -
3. The understanding of the rules of converting to binary.
- -
With all the above in mind, we can begin to understand the algorithm.
Rule 1:
We take the 8-bit binary from right to left, corresponding to the number 2 to the power of 0 (2 ^ 0) to the power of 2 to the 7 (2 ^ 7). Then write it as follows:
1111 1111128-64-32-16 8-4-2-1
This is not difficult to understand, remember this on ok.
Rule 2:
Set X (0)