PHP Integer Format
<?php
$number = 0x12A;
$string = '0x12A';
// direct decoding
echo hexdec($string);
// the reverse way
$newString = '0x'.dechex($number);
?>
PHP has several convenient integer format to write them in a proper way: 0x12F, 0b110101, 0o12367. This works well as part of the code
When such formats are provided as a string, it may be processed with the ad hoc native functions such as hexdec(), bindec() or octdec() : they convert a number between bases, and they also accept the native PHP formats.
For the reverse operation, the reverse functions are also useful, with an extra header for the format.
See Also
- Integer (PHP manual)
- hexdec
- octdec
- bindec
- dechexdec
- decoctdec
- decbindec
- converting and back [Try me]
PHP Features
Last updated: 10 September 2026