Hexidecimal Math

December 20, 2024 note-to-self

Can I do math in hexidecimal??

Note: this is not the "word" abc123. This is the number abc123 as represented in hexidecimal.

Each "place" is 16^<place>.

So abc123:

  • a place is 16^5 or 1,048,576
  • b place is 16^4 or 65,536
  • c place is 16^3 or 4,096
  • 1 place is 16^2 or 256
  • 2 place is 16^1 or 16
  • 3 place is 16^0 or 1 (not 0!)

Thus (a in hexidecimal means 10, remember, etc, etc.):

  • a = 10 x 1048576 or 10,485,760
  • b = 11 x 65536 or 720,896
  • c = 12 x 4096 or 49,152
  • 1 = 1 x 256 or 256
  • 2 = 2 x 16 or 32
  • 3 = 3 x 1 or 3

11,256,099?

(confirmed with: php -r "echo hexdec('abc123');")

Hex yeah!!