Hexadecimal (Base 16 Numbers)

The base 10 numbering system is the numbering system we all know and love.  It’s called base “10” because there are 10 unique digits to represent all values.  Those digits are 1-9, plus the zero digit, for a total of 10.

There are other numbering systems with different amounts of digits.  For example, binary only has two digits (1 and 0), Octal has 8 digits (0-7), then there’s base 10 (0-9), and finally Hexadecimal (or just “Hex” for short), which is base 16, with 16 unique digits (0-9, A-F).

To count in hex, you start just like you do in decimal (“decimal” is another name for our familiar base 10 numbering system):

  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

But, in hex, you don’t carry a 1 once you pass 9, like you do in decimal.  Instead, you just keep counting with single digits.  Hex uses the letters A, B, C, D, E, & F as numerical digits.  So, to continue counting past 9…

  • A
  • B
  • C
  • D
  • E
  • F

Just like in decimal, when we reach our last digit, we carry a one and start over:

  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 1A
  • 1B
  • 1C
  • 1D
  • 1E
  • 1F
  • 20
  • 21

etc…

Note that 10 in decimal is “ten”, but 10 in hexadecimal is “sixteen”.  How do you determine whether someone means ten or sixteen when they write 10?  Well, if they don’t put any special symbols before or after the 10, then it’s assumed to be base 10 (or “decimal”).  If they intend for it to be hexadecimal, then they write it like this: $10  or like this: 10h  or like this: x10  or like this: #10.

What is hexadecimal used for?

It’s used primarily in computer programming.  It turns out that hex converts well from binary and back again.  We all know how computers like binary.  Though, binary is difficult to read, even for programmers, and binary numbers take up a lot of space.  For example, 100000000 in binary is the same as 256 in decimal.  To display that same value in hex, it’d be $100.  Just a side note:  If you subtract one from that number, here’s what it’d look like in binary, hex, and decimal:

  • 11111111% (binary)
  • 255 (decimal)
  • $FF (hex)

Every character in a hex number, equates directly to 4 binary digits.  This is what makes hexadecimal and binary such good bases to convert between.  Another thing that makes hex good for programming is that 2 hex digits represent 8 bits, which is a byte.  So, any byte value is simply 2 hex digits.

Have you ever looked at the HTML code that makes up a web page?  Just open your View menu in your browser right now and choose “Source” or “Page Source”.  Somewhere in that HTML code you’ll see something about color, then a 6 character hex number.  One common hex number in HTML code is #FFFFFF.  This is because most computer displays can display 16.7 million colors.  16.7 million happens to be the largest number than can be represented in 24 bits.  24 bits is 3 bytes.  3 bytes can be represented with 6 hex digits.  Color information is represented with 3 bytes.  Each byte being a value between 0 and 255 inclusive.  The 1st byte represents the shade of red.  The 2nd, green, the 3rd, blue.  Combinations of those 3 primary colors make up all the 16.7 million colors (256*256*256 = 16.7 million).  So, the color value represented by the hex number #FFFFFF says the red shade should be at it’s brightest (the first “FF”), as well as the green and the blue shades.  When all 3 primary colors are equal, you get a shade of gray.  When they’re all maxed out, you get white.  So, #FFFFFF represents the color white.  #FF0000 is red.  #00FF00 is green.  #0000FF is blue.  #FF00FF is purple (all red, all blue, no green), etc…

Leave a Reply