PHP function chapter in decimal, Binary, octal and 16 conversion function Description _php Tips

Source: Internet
Author: User
One, decimal (decimal System) conversion function description
1, decimal to Binary decbin () function, as follows example

Echo Decbin (12); Output 1100
Echo Decbin (26); Output 11010
Decbin
(PHP 3, PHP 4, PHP 5)
Decbin--Decimal conversion to Binary
Description
string Decbin (int number)
Returns a string containing the binary representation of a given number parameter. The maximum number that can be converted is 4294967295 in decimal, and the result is a string of 32 1.

2, decimal octal decoct () function

Echo decoct (15); Output 17
Echo decoct (264); Output 410
Decoct
(PHP 3, PHP 4, PHP 5)
DECOCT-Decimal conversion to octal
Description
string decoct (int number)
Returns a string containing the octal representation with the given number parameter. The maximum number that can be converted is 4294967295 in decimal, and the result is "37777777777".

3, decimal turn hexadecimal dechex () function

Echo Dechex (10); Output A
Echo Dechex (47); Output 2f
Dechex
(PHP 3, PHP 4, PHP 5)
Description
string Dechex (int number)
Returns a string containing the hexadecimal representation of a given number parameter. The maximum number that can be converted is 4294967295 in decimal, and the result is "FFFFFFFF".

two, binary (binary system) conversion function Description
1, binary turn 16 into Bin2Hex () function

\$binary = "11111001";
\$hex = Dechex (Bindec (\$binary));
echo \$hex;/output F9
Bin2Hex
(PHP 3 >= 3.0.9, PHP 4, PHP 5)
Bin2Hex-converts binary data to hexadecimal representation
Description
String Bin2Hex (String str)
Returns the ASCII string, which is the hexadecimal representation of the parameter str. The conversion uses the byte method, the high four bit byte first.

2, binary turn 10 into Bindec () function

echo bindec (' 110011 '); Output 51
echo bindec (' 000110011 '); Output 51
Echo Bindec (' 111 '); Output 7
Bindec
(PHP 3, PHP 4, PHP 5)
Bindec--Binary conversion to decimal
Description
Number Bindec (String binary_string)
Returns the decimal value of the binary number represented by the binary_string parameter.
Bindec () converts a binary number to an integer. The maximum number that can be converted is 31 digits 1 or decimal 2147483647. PHP 4.1.0 begins, the function can handle large numbers, in which case it returns the float type.

three, octal (octal system) conversion function Description
Octal decimal octdec () function

Echo Octdec (' 77 '); Output 63
Echo Octdec (DECOCT (45)); Output 45
Octdec
(PHP 3, PHP 4, PHP 5)
Octdec-Eight conversion to decimal
Description
Number Octdec (String octal_string)
Returns the decimal equivalent of the number of octal represented by the octal_string parameter. The maximum number that can be converted is 17777777777 or decimal 2147483647. PHP 4.1.0 begins, the function can handle large numbers, in which case it returns the float type.

Var_dump (Hexdec ("the"));
Var_dump (Hexdec ("ee"));
Both print "int (238)"

Var_dump (Hexdec ("that")); print "int (10)"
Var_dump (Hexdec ("A0")); print "int (160)"
Hexdec
(PHP 3, PHP 4, PHP 5)
Hexdec-16 Conversion to decimal
Description
Number Hexdec (String hex_string)
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 in decimal. PHP 4.1.0 begins, the function can handle large numbers, in which case it returns the float type.
Hexdec () Replaces all non-hexadecimal characters encountered with 0. In this way, all 0 left are ignored, but the right 0 is in the accounting value.

Five, Arbitrary conversion base_convert () function

Echo Base_convert (\$hexadecimal, 16, 2);//Output 101000110111001100110100
Base_convert
(PHP 3 >= 3.0.6, PHP 4, PHP 5)

Base_convert--converting numbers between arbitrary systems
Description
String Base_convert (string number, int frombase, int tobase)
Returns a string containing the representation of number in tobase. The number itself is specified by Frombase. Frombase and Tobase are only between 2 and 36 (including 2 and 36). Numbers above decimal are represented by a letter A-Z, for example a denotes 10,b 11 and Z represents 35.

Here is the main PHP conversion function to organize, easy to develop and find, the relevant specific function description please refer to the PHP manual. Please pay attention to the next issue of the text character encoding Research series.
Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.