1. Advertising
    y u no do it?

    Advertising (learn more)

    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.
    SEMrush
     
    Trent Violence, Jan 23, 2009 IP
    SEMrush
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    
    $hex = 0x1A + 0x2A; // 68
    
    PHP:
     
    Kaizoku, Jan 23, 2009 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,152
    Likes Received:
    88
    Best Answers:
    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.
     
    joebert, Jan 24, 2009 IP
  4. bird.23

    bird.23 Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    $hex1 = FF;
    $hex2 = AB;
    $dec1 = hexdec($hex1);
    $dec2 = hexdec($hex2);
    $sum = $dec1 +$dec2;
    echo "Sum is :$sum <br />";
    ?>
     
    bird.23, Jan 24, 2009 IP
  5. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #5
    How unnecessary... Not to mention FF is a horrible way of using hex...
    
    <?php
    
    $hex1 = 0x1F;
    $hex2 = 0x10;
    
    echo $hex1 + $hex2;
    PHP:
     
    Danltn, Jan 24, 2009 IP