Hey guys, for a page on my site, I'm needing to do some hex math operations, I know I could probably convert the hex to a decimal and do the math that way, but I'm wondering if there's an easier, more direct way. Any help is greatly appreciated.
Assuming your hexedecimal inputs will be variable, and tend to be strings when you get them, the only option I see is using hexdec or base_convert and working from there, like you were thinking in the first place.
<?php $hex1 = FF; $hex2 = AB; $dec1 = hexdec($hex1); $dec2 = hexdec($hex2); $sum = $dec1 +$dec2; echo "Sum is :$sum <br />"; ?>
How unnecessary... Not to mention FF is a horrible way of using hex... <?php $hex1 = 0x1F; $hex2 = 0x10; echo $hex1 + $hex2; PHP: