Original PHP: binary, octal, hexadecimal, and mutual computing
In the previous chapter, binary, octal, hexadecimal, and reciprocal calculation are one,
This article focuses on the mutual calculation between binary, octal, and hexadecimal, and how to convert the binary into decimal.
How can we convert decimal to binary, octal or hexadecimal?
In fact, it is very simple. if you want to convert it to binary, divide the decimal number by 2 until the quotient is 0, and then obtain the remainder value first.
After sorting, you can get the value above and put it together.
How about converting decimal to octal ?, Just change the divisor to eight,
Hexadecimal format? That must have changed the divisor to sixteen.
Next we will explain in detail
- Convert decimal to binary
Convert a decimal number of 11 to binary. the calculation procedure is as follows:
Expression quotient remainder
11 Jun 2 5 1
5 then 2 2 1
2 bytes 2 1 0
1 limit 2 0 1
Finally, we sorted the result in the descending order as 1011. how is it easy?
Decimal number 17 to octal. calculation procedure
Expression quotient remainder
17 listen 8 2 1
2 bytes 8 0 2
Finally, we sorted the result in the descending order as 021. how is it easy?
- Convert decimal to hexadecimal
Convert the decimal number 22 to the hexadecimal format. the calculation procedure is as follows:
Expression quotient remainder
22 Jun 16 1 6
1 limit 16 0 1
Finally, we sorted the result in the descending order as 0 × 16. how is this simple?
This is the end ..
In fact, it is very easy to get into the number.