Conversion between hexadecimal
Our computer stores binary values, which can also be converted by php. In this case, we can tell you in a simple way that this blog is just a note for study.
10 to others (2, 8, 16)
Rule: decimal number, divided by the target base. The remainder and operator are obtained. If the operator is not zero, continue to divide the operator by the target system to obtain the remainder and operator. Until the operator is zero, connect all the remainder from the bottom to the bottom:
$ Int = 1234;
// 10 to 8
// 1234
// 8
// 154 2
// 8
// 19 2
// 8
// 2 3
// 8
// 0 2
//
//
Convert others (, 16) to 10
Rule: Use the number on each digit, multiplied by the power of the weight in the forward order, so that the result can be accumulated.
Weight, starting from the low position to 0, in turn + 1 to the high position;
/// 10 to 16
// 1234
// 16
// 77 2
// 16
// 4 13 (D)
// 16
// 0 4
//
// 16 to 10
// Weight: 210
// 4D2
// 4*16 ^ 2 + D * 16 ^ 1 + 2*16 ^ 0
// = 4*256 + 13*16 + 2*1
// = 1024 + 208 + 2 = 1234
//
// 8 to 10
// 3210
// 2322
// 2*8 ^ 3 + 3*8 ^ 2 + 2*8 ^ 1 + 2*8 ^ 0
In the program, the hexadecimal conversion function:
Dec, 10
Bin, 2
Oct, 8
Hex, 16
Decbin (); 10to2
Dechex (); 10 to 16
Octdec (); 8 to 10
For example:
Function parameters, which are expected to be strings.