## 2.15.1. ProblemYou need to convert a number from one base to another. ## 2.15.2. SolutionUse the $hex = 'a1'; // hexadecimal number (base 16) // convert from base 16 to base 10 $decimal = base_convert($hex, 16, 10); // $decimal is now 161 ## 2.15.3. DiscussionThe There are also a few specialized functions for conversions to and from base 10 and the most commonly used other bases of 2, 8, and 16. They're // convert to base 10 print bindec(11011); // 27 print octdec(33); // 27 print hexdec('1b'); // 27 // convert from base 10 print decbin(27); // 11011 print decoct(27); // 33 print dechex(27); // 1b Another alternative is to use For instance, say you want to print out HTML color values: printf('#%02X%02X%02X', 0, 102, 204); // #0066CC ## 2.15.4. See AlsoDocumentation on |

PHP Cookbook: Solutions and Examples for PHP Programmers

ISBN: 0596101015

EAN: 2147483647

EAN: 2147483647

Year: 2006

Pages: 445

Pages: 445

Authors: Adam Trachtenberg, David Sklar

flylib.com © 2008-2017.

If you may any questions please contact us: flylib@qtcs.net

If you may any questions please contact us: flylib@qtcs.net