PHP binary Conversion
A. Decimal
1. Decimal-to-binary decbin () function: Returns a string containing the binary representation of the given number parameter. The maximum value that can be converted is a decimal of 4294967295, and the result is a string of 32 1.
2. Decimal to octal decoct () function: Returns a string containing an octal representation of the given number parameter. The maximum value that can be converted is a decimal of 4294967295, and the result is "37777777777".
3. Decimal to hexadecimal Dechex () function: Returns a string containing the hexadecimal representation of the given number parameter. The maximum value that can be converted is 4294967295 in decimal and the result is "FFFFFFFF".
Two. Binary
1. Binary turn 16 into Bin2Hex () function: Returns the ASCII string, which is the hexadecimal representation of the parameter str. The conversion uses byte mode, and the high four-bit byte takes precedence.
2. Binary turn 10 into Bindec () function:: Bindec () converts a binary number to an integer. The maximum number of convertible is 31 bits 1 or decimal 2147483647. Starting with PHP 4.1.0, the function can handle large values, in which case it returns a float type.
Three. Eight binary
Octal decimal Octdec () function: Returns the decimal equivalent of the octal number represented by the octal_string parameter. The maximum number of convertible values is 17777777777 or decimal 2147483647. PHP 4.1.0 begins, the function can handle large numbers, in which case it returns a float type.
Four. 16 Binary
hexadecimal to decimal hexdec () function: Returns the decimal number equivalent to the hexadecimal number represented by the hex_string parameter. Hexdec () converts a hexadecimal string to a decimal number. The maximum value that can be converted is 7FFFFFFF, which is 2147483647 of the decimal. PHP 4.1.0 begins, the function can handle large numbers, in which case it returns a float type.
Hexdec () Replaces all non-hexadecimal characters encountered with 0. This way, all the left 0 are ignored, but the 0 on the right is counted into the value.
Five. Arbitrary binary conversion Base_convert () function
Base_convert-converts numbers between arbitrary conversions: Returns a string containing the representation of number in the Tobase binary. The binary of number itself is specified by Frombase. Both Frombase and tobase can only be between 2 and 36 (including 2 and 36). Numbers above the decimal are expressed in letters A-Z, for example a means that 10,b represents 11 and Z represents 35.
eg.
$hexadecimal = ' A37334 ';
Echo Base_convert ($hexadecimal, 16, 2);//Output 101000110111001100110100