PHP - Number: Converting Between BasesTag: number, convert Category: PHP Application, PHP Basicpost: 16 Mar 2008 read: 40 PHP Number Tips - Part 4: If you want to convert a number to a different base such as binary, octal, hexadecimal, or custom, so you can use PHP's decbin( ), decoct( ), dexhec( ), or base_convert( ) functions such as:
PHP comes with the number of functions to convert a number from one base to another. In the above, the listing takes a base-10 (decimal) number and converts it to binary, octal, and hexadecimal wiith the decbin( ), decoct( ), and dechex( ) functions respectively. To convert in the opposite direction, you only have to use the bindec( ), octdec( ), and hexdec( ) functions. If you need to convert a number to or from a custom base, you can use the base_convert( ) function which accepts three arguments: the number, the base it's currently in, and the base it's to be converted to. Here is the example of using the dechex( ) function:
|
| | Give Your Opinion | Recommend |
|

