y u no do it?

Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

Starts at just \$1 per CPM or \$0.10 per CPC.

# Wondering how to do Hex Math in PHP

Discussion in 'PHP' started by Trent Violence, Jan 23, 2009.

1. #1
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.

Jan 23, 2009 IP
2. ### KaizokuWell-Known Member

Messages:
1,261
20
1
Trophy Points:
105
#2
``````
\$hex = 0x1A + 0x2A; // 68
``````
PHP:

Jan 23, 2009 IP
3. ### joebertWell-Known Member

Messages:
2,152
88
0
Trophy Points:
145
#3
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.

Jan 24, 2009 IP
4. ### bird.23Peon

Messages:
13
1
0
Trophy Points:
0
#4
<?php
\$hex1 = FF;
\$hex2 = AB;
\$dec1 = hexdec(\$hex1);
\$dec2 = hexdec(\$hex2);
\$sum = \$dec1 +\$dec2;
echo "Sum is :\$sum <br />";
?>

Jan 24, 2009 IP
5. ### DanltnPeon

Messages:
679
36
0
Trophy Points:
0
#5
How unnecessary... Not to mention FF is a horrible way of using hex...
``````
<?php

\$hex1 = 0x1F;
\$hex2 = 0x10;

echo \$hex1 + \$hex2;``````
PHP:

Jan 24, 2009 IP