How do I convert a binary number (i.e. 1111111) to hexadecimal (i.e. 7f) using PHP? I recognize I could do dechex(bindec(\'1111111\'));, h
1111111
7f
dechex(bindec(\'1111111\'));
Your solution is fine. You can also use base_convert.
$binary = '1111111'; echo base_convert($binary, 2, 16); // 7f
But keep in mind that php is not built for calculations. It is built for working with strings.