Hexadecimal Number System

Download as PDF

Ever wonder how computers pick the exact color for your screen? They use a special 'secret code' called the hexadecimal number system! It might look strange with its letters, but it’s a super useful way of counting that you can learn right now.

Hexadecimal Number System — an original Algebra911 reference diagram defining hexadecimal number system and a worked example.
Hexadecimal Numbers Explained: The Secret Code of Computers

What Is the Hexadecimal Number System?

The hexadecimal number system is a way of counting that uses a base of 16 instead of the base-10 system we use every day. Our normal number system, called decimal or base-10, uses ten different digits to write any number: 0,1,2,3,4,5,6,7,8, and 9. Once we count past 9, we add a new place value and write 10, which means 'one group of ten and zero ones'.

The hexadecimal system, or base-16, needs more symbols because it counts in groups of sixteen. It uses the same ten digits we're used to (0 through 9), but then it needs six more symbols to represent the values for ten, eleven, twelve, thirteen, fourteen, and fifteen. For these, we use the first six letters of the alphabet: A, B, C, D, E, and F.

So, in hexadecimal (often shortened to just "hex"), the digits are:

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

It might seem strange to use letters as numbers, but once you get the hang of it, you'll see it's just another way of organizing numbers, one that is incredibly useful for computers.

Why Do We Use Hexadecimal Numbers?

If we have a perfectly good base-10 system, why bother with a complicated base-16 system that uses letters? The answer lies inside our computers. At their most basic level, computers don't think in base-10. They think in binary, which is base-2. Binary only uses two digits: 0 and 1.

A computer stores all information—from the words in this lesson to the colors on your screen—as incredibly long strings of zeros and ones, like 1101011010110010. As you can imagine, it's very easy for a human to make a mistake when reading or writing such a long number. This is where hexadecimal becomes a hero!

The number 16 is a power of 2 (16=24). This creates a special relationship between hex and binary. It means that exactly one hexadecimal digit can be used to represent a group of four binary digits.

  • For example, the binary string 1101 is equal to 13 in decimal, which is the digit D in hexadecimal.
  • The long binary number from before, 1101011010110010, can be broken into four groups: 1101 0110 1011 0010.
  • In hex, this becomes D6B216.

Which one would you rather write down? 11010110101100102 or D6B216? Hexadecimal acts as a much shorter, more human-friendly language to express the binary information that computers use. You see it in many places in technology:

  • Web Colors: To tell a web browser exactly which shade of blue to show, you use a hex code like #0000FF.
  • Memory Addresses: Computers use hex to label locations in their memory, like 0x7FFF.
  • Error Codes: When a program crashes, it might show an error code like 0x80070005 that helps developers figure out what went wrong.

The Hexadecimal Digits: 0-9 and A-F

The key to understanding hexadecimal is to get comfortable with its sixteen digits. The first ten are easy, as they are the same as our decimal system. The next six are letters that represent the decimal values from 10 to 15. It's very important to remember that in this context, 'A' is not a letter; it is the number ten.

Here is a table that shows each hexadecimal digit and its decimal equivalent. This is a great chart to keep handy as you're learning!

Hexadecimal DigitDecimal Value
00
11
22
33
44
55
66
77
88
99
A10
B11
C12
D13
E14
F15

When you're counting in hex, you go up the list. After 9, the next number isn't 10, it's A. Then B, C, D, E, and F. What comes after F? Just like in decimal where we run out of digits after 9 and write 10, in hex we run out of digits after F and write 1016. This hex number 1016 means 'one group of sixteen and zero ones,' which is equal to 16 in our decimal system.

How Do You Convert from Hexadecimal to Decimal?

Converting a hexadecimal number to a decimal number is all about understanding place value. In our familiar decimal system, each place represents a power of 10. For the number 345, we know it means:

34510=(3×102)+(4×101)+(5×100)=300+40+5

Hexadecimal works the exact same way, but the place values are powers of 16.

  • The rightmost place is the ones place (160=1).
  • The next place to the left is the sixteens place (161=16).
  • The next place is the two-hundred-fifty-sixes place (162=256), and so on.
Hex to Decimal: (dn...d2d1d0)16=(dn×16n)+...+(d2×162)+(d1×161)+(d0×160)

To convert any hex number to decimal, you follow these steps:

  1. Write down the hex number and identify the place value for each digit (160,161,162, etc., from right to left).
  2. If any digit is a letter (A-F), convert it to its decimal value (10-15).
  3. Multiply each digit's decimal value by its corresponding place value.
  4. Add all these products together. The sum is your answer in decimal.
Example 1

Convert the hexadecimal number 3B716 to its decimal equivalent.

Step 1: Identify the digits and their place values.

The digits are 3, B, and 7. From right to left, the place values are 160, 161, and 162.

  • 7 is in the 160 (ones) place.
  • B is in the 161 (sixteens) place.
  • 3 is in the 162 (two-hundred-fifty-sixes) place.

Step 2: Convert letter digits to their decimal values.

The digit B is equal to 11 in decimal.

Step 3 & 4: Multiply and add.

We multiply each digit's value by its place value and sum the results.

(3×162)+(B×161)+(7×160) =(3×256)+(11×16)+(7×1) =768+176+7 =951

So, 3B716=95110.

How Do You Convert from Decimal to Hexadecimal?

Going the other way, from decimal to hexadecimal, uses a cool math trick involving repeated division. The goal is to figure out how many groups of 16, 256, and so on, fit into our decimal number. The remainders from our division will become the digits of our hex number.

Follow these steps:

  1. Take your decimal number and divide it by 16.
  2. Write down the whole number part of the answer (the quotient) and the remainder. The remainder will be a number from 0 to 15.
  3. Convert the remainder to its hexadecimal digit (for example, if the remainder is 10, the digit is A). This is your first hex digit (the rightmost one).
  4. Take the quotient from step 2 and divide it by 16 again.
  5. Repeat this process, writing down the new remainder's hex digit to the left of the previous one.
  6. Continue until your quotient is 0. The hex number is the sequence of remainders you found, read from the bottom up.
Example 2

Convert the decimal number 85910 to its hexadecimal equivalent.

We will use repeated division by 16.

Step 1: Divide 859 by 16.

859÷16=53 with a remainder of 11

The remainder is 11. The hexadecimal digit for 11 is B. This is our rightmost digit.

Step 2: Divide the quotient (53) by 16.

53÷16=3 with a remainder of 5

The remainder is 5. The hexadecimal digit for 5 is 5. This digit goes to the left of the B.

Step 3: Divide the new quotient (3) by 16.

3÷16=0 with a remainder of 3

The remainder is 3. The hexadecimal digit for 3 is 3. This digit goes to the left of the 5.

Step 4: Read the remainders from the bottom up.

Our quotients have reached 0, so we are done. Reading the hexadecimal digits of our remainders from the last one to the first one, we get 3, then 5, then B.

So, 85910=35B16.

A Colorful Application: Hex Codes in Digital Design

One of the most common places you'll encounter hexadecimal numbers is in web design and digital art. Colors on a computer screen are created by mixing different amounts of red, green, and blue light. This is known as the RGB color model.

Each of these three colors (Red, Green, and Blue) is assigned an intensity value from 0 (none of that color) to 255 (the maximum amount). Why 255? Because a two-digit hexadecimal number can represent exactly 256 different values (from 0 to 255).

  • 0016=010 (minimum intensity)
  • FF16=(15×16)+(15×1)=240+15=25510 (maximum intensity)

A hex color code is a six-digit hex number, usually starting with a hashtag (#). The six digits are actually three pairs of two-digit hex numbers, representing the amount of Red, Green, and Blue light:

#RRGGBB

  • The first two digits (RR) are for Red.
  • The middle two digits (GG) are for Green.
  • The last two digits (BB) are for Blue.
Example 3

What color is represented by the hex code #E67E22?

Step 1: Break the code into its R, G, and B components.

  • RR = E616
  • GG = 7E16
  • BB = 2216

Step 2: Convert each two-digit hex number to its decimal equivalent (from 0-255).

Red: E616=(E×161)+(6×160)=(14×16)+(6×1)=224+6=230

Green: 7E16=(7×161)+(E×160)=(7×16)+(14×1)=112+14=126

Blue: 2216=(2×161)+(2×160)=(2×16)+(2×1)=32+2=34

Step 3: Interpret the result.

The RGB value is (230,126,34). This means the color has a very high amount of red, a medium amount of green, and a very low amount of blue. This combination creates a shade of orange.

Common Mistakes to Avoid

As you start working with hexadecimal numbers, there are a few common pitfalls to watch out for. Being aware of them can save you a lot of confusion!

  • Forgetting Letters are Numbers: The most common mistake is seeing a letter like 'C' and not immediately thinking of it as the number 12. When you are converting from hex to decimal, you must substitute the decimal value of the letter before you multiply by the place value.
  • Place Value Errors: When converting from hex, always remember the place values are powers of 16 (1,16,256,...), not powers of 10 (1,10,100,...). It's easy to slip back into the habit of using the decimal system's place values.
  • Reading Remainders Backwards: When converting from decimal to hex using the division method, the remainders must be read from the bottom up. The last remainder you calculate is the first (leftmost) digit of your hex number. Reading them top-down will give you the wrong answer.
  • Mixing Up Conversion Methods: There are two different processes: one for hex-to-decimal (multiplication and addition) and one for decimal-to-hex (repeated division). Don't try to use division to convert from hex to decimal, or multiplication to go from decimal to hex. Keep the two methods separate in your mind.
  • Forgetting a Zero Remainder: If you divide by 16 and get a remainder of 0, you must write down 0 as that place's hex digit. It's a placeholder, just like in the number 205, and is very important.

Quick Summary

Here are the most important points to remember about the hexadecimal number system:

  • Base-16: The hexadecimal system is a base-16 system.
  • 16 Symbols: It uses sixteen unique symbols for its digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
  • Letter Values: The letters A-F represent the decimal values 10-15.
  • Place Values: The place values are powers of 16, such as 160=1, 161=16, 162=256, and so on.
  • Hex to Decimal Conversion: To convert a hex number to decimal, multiply each digit by its place value and then add all the results together.
  • Decimal to Hex Conversion: To convert a decimal number to hex, use repeated division by 16 and read the remainders from the bottom up.
  • Computer Language: Hexadecimal is used in computing as a human-friendly shorthand for binary code, especially for things like colors, memory addresses, and error codes.

Frequently Asked Questions

Why is it called 'base-16'?

Because it uses 16 unique symbols for its digits (0-9 and A-F). The 'base' of a number system tells you how many symbols it uses. Our regular decimal system is 'base-10' because it uses ten symbols (0-9).

Why does hexadecimal use letters?

We need 16 different symbols, but we only have 10 number digits (0 through 9). To get the other six symbols we need, we use the first six letters of the alphabet, A, B, C, D, E, and F, to represent the numbers 10 through 15.

What comes after the number F in hexadecimal?

Just like 9 is followed by 10 in our decimal system, F16 (which is 15) is followed by 1016. This isn't the number ten! It represents one group of sixteen and zero ones, so 1016 is equal to 16 in decimal.

Where will I see hexadecimal numbers in real life?

You see them all the time on computers! They are used to define colors on web pages (like #FFD700 for gold), in Wi-Fi passwords, and in error messages your computer might show. They are a shorthand for the computer's own language.

Is it hard to learn hexadecimal?

It might seem strange at first because of the letters, but it's not hard once you understand the two main ideas. You just need to remember the place values are powers of 16 and that A-F stand for 10-15.

Can you do addition and subtraction with hexadecimal numbers?

Yes, you absolutely can! It works very much like regular addition and subtraction, but you have to remember to 'carry over' or 'borrow' groups of 16 instead of groups of 10. It's a bit more advanced, but it follows similar rules.

Why is hexadecimal so important for computers?

Computers work with binary (0s and 1s), which creates very long, unreadable numbers. Since 16 is a power of 2 (24), one hex digit can stand for exactly four binary digits. This makes hexadecimal a neat and tidy way for programmers to read and write computer data.