How to do simple Maths with Hex?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mikeeeeeeey
Forum Contributor
Posts: 130
Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK

How to do simple Maths with Hex?

Post by mikeeeeeeey »

Hi guys,

How would I do compare two Hex numbers to find their difference?

I've tried hexdec() and then adding/subtracting but some of these numbers vastly differ, and simply doing $hex_number - $hex_number2 always returns 0.

Anyone know anything about this?

Thanks in advance
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to do simple Maths with Hex?

Post by Christopher »

You could use base_convert(), or maybe try something like:

Code: Select all

"0x$hex_number" - "0x$hex_number2"
(#10850)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: How to do simple Maths with Hex?

Post by Kieran Huggins »

base_convert() FTW!
Post Reply