PHP base_convert () binary number conversion function _php Tutorial

Source: Internet
Author: User
The Base_convert () function converts numbers between arbitrary binaries.

Grammar
Base_convert (number,frombase,tobase) parameter description
Number required. The original value.
Frombase required. The original binary of the number.
Tobase required. The binary to convert.


*/

$hexadecimal = ' a37334 ';
Echo Base_convert ($hexadecimal, 16,2); Convert to binary output 101000110111001100110100
echo "
";
$number = "123";
Echo Base_convert ($number, 10,2); Convert to binary output 1111011
echo "
";
Echo Base_convert ($number, 10,8); Convert to octal output 173
echo "
";
Echo Base_convert ($number, 10,16); Convert to hexadecimal output 7b
$number 2 = "100000101";
echo "
";
Echo Base_convert ($number 2,2,10); Convert to decimal output 261
echo "
";
Echo Base_convert ($number 2,2,8); Convert to octal output 405


/*
Description
Returns a string that contains 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.


http://www.bkjia.com/PHPjc/445382.html www.bkjia.com true http://www.bkjia.com/PHPjc/445382.html techarticle the Base_convert () function converts numbers between arbitrary binaries. The syntax Base_convert (number,frombase,tobase) parameter describes number required. The original value. Frombase required. The original binary of the digital ...

  • Contact Us

    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.