Hexadecimal

What is Hexadecimal

The language computers communicate in is quite distinct from our usual decimal system of numbers. Computers rely on a different number system called "hexadecimal," which is derived from the Latin words "hexa" (meaning six) and "decem" (meaning ten). This system is essential because computers communicate using switches that can be in one of two positions: on (1) or off (0).

Now, you might wonder why computers opt for this hexadecimal system instead of the decimal system that we're accustomed to, which spans from 0 to 9. The reason is that hexadecimal simplifies things for computers by utilizing sixteen different symbols: '0' through '9' and 'A' through 'F'. These symbols correspond to values from 0 to 15.

This hexadecimal language is related to a code that computers effortlessly comprehend. The 1s and 0s in binary are comparable to the hexadecimal system's digits. When these digits are arranged together, like threading beads onto a string, they can symbolize intricate information.

In the practical realm, computers incorporate billions of these binary digits to undertake various tasks. Employing the hexadecimal system offers many advantages, including streamlined construction of reliable and efficient systems. The effectiveness of hexadecimal stems from the ease with which electronic components process and store binary data.

So, while hexadecimal may appear unfamiliar, it is an optimal mode of communication and thought for computers. It is a language specially tailored for these machines to converse with one another and perform intricate computations.

The Importance of Hexadecimal

Here is why understanding hexadecimal is an important skill in computer science: 

So, hexadecimal is like a secret code language for computers. Learning it can help you understand and work with computers better, whether you are designing games, solving puzzles, or just exploring the digital world.

How Does Hexadecimal Work

Above, we saw what hexadecimal is and why it is important, but how does it work? The language of computers is built on the foundation of switches – like tiny buttons that can either be switched off (0) or on (1). This binary system might seem strange at first, but it's perfectly suited for computers because their internal parts, like transistors, can easily flip between these two states.

Now, let's dive into something called hexadecimal. Think of it as a new language that computers use to talk among themselves. Just like binary, it's all about switches, but hexadecimal goes a step further to make things easier for both computers and us humans.

In decimal, we have digits from 0 to 9. In binary, we only have 0 and 1. Hexadecimal takes it up a notch by adding more symbols – not just numbers but also letters like A, B, C, D, E, and F. These symbols represent values from 0 to 15. It is like having a bigger vocabulary that allows us to express more things.

Imagine counting in hexadecimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, and so on. When we reach F, it's like moving from 9 to 10 in decimal – a new column starts. This helps us represent larger values without using too many symbols.

Hexadecimal is a super useful language for computers. It is like a bridge between binary, which computers love, and the human-friendly decimal system we are used to. It is a language that allows computers to talk to each other efficiently and helps programmers write code that is both powerful and easy to understand.

So, while it might seem like a puzzle at first, hexadecimal is a valuable tool that lets us unlock the full potential of computers and their amazing abilities. It is a language of simplicity and power, making it an essential part of the digital world we live in.

Counting in Hexadecimal

Picture hexadecimal as a fresh language that computers employ for communication. Like binary, it centers around switches, but hexadecimal adds a layer of simplicity that benefits computers and humans.

In decimal, we use digits ranging from 0 to 9. In binary, we're limited to just 0 and 1. Hexadecimal elevates this further by introducing more symbols – not solely numbers, but letters like A, B, C, D, E, and F. These symbols correspond to values from 0 to 15, expanding our vocabulary to convey more intricate concepts.

Consider counting in hexadecimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, and so on. Reaching F is similar to transitioning from 9 to 10 in decimal – initiating a new column. This approach facilitates the representation of larger values without resorting to numerous symbols. So, after reaching F, the next value is 10 (the decimal equivalent is 16), then 11, 12, 13... 1A, 1B, 1C, 1D, 1E, 1F, 20, 21, and so on. Try using these cards to get a feel for how this numbering system works: Hexadecimal Cards With Decimal Value.

Hexadecimal proves invaluable to computers. It serves as a bridge between the beloved binary system and the more user-friendly decimal system we employ. This language enables efficient communication among computers and empowers programmers to craft code that is both robust and easy to understand.

Although it might initially seem like a puzzle, hexadecimal is a potent tool that grants us access to the full potential of computers and their remarkable capabilities. It embodies simplicity and prowess, rendering it an integral facet of the digital universe in which we reside.

Converting DEcimal to Hexadecimal

Converting a number from decimal or base-10 into hexadecimal is like translating a message. Let us break it down into steps.


Step 1: First, divide the decimal number by 16, considering the number as an integer (whole number).


Step 2: Keep aside the remainder (multiply the value after the decimal point by 16).


Step 3: Again divide the quotient by 16 and repeat until you get the quotient value equal to zero.


Step 4: Now take the values of each remainder left in the reverse order to get the hexadecimal numbers.


Note: Remember, from 0 to 9, the numbers will be counted as the same in the decimal system. But from 10 to 15, they are expressed in alphabetical order from A to F.


Sample Problem With Explanation

Let us follow these steps to convert 267 into hexadecimal. Follow along, making your calculations on a piece of scrap paper.


Step 1: Start by dividing the number by 16...   267 ÷ 16 = 16.6875.


Step 2: Now, we need to find the remainder. To do this, we take the part after the decimal point (0.6875) and multiply it by 16... 

0.6875 x 16 = 11. If it is greater than 9, we write it as its hexadecimal equivalent (A-F). In this case, 11 is written as 'B'.


Step 3: We keep that 'B' as the first part of the answer. Write it off to the side of your calculations.


Step 4: We repeat this process with the whole number part from Step 1, which is 16. We divide it by 16 again...   16 ÷ 16 = 1.0.


Step 5: Now, we find the remainder for this new number. In this case, it is 0...   0 x 16 = 0. 


Step 6: We add this new remainder to the left of our previous one (0B). Again, keep this off to the side of your calculations.


Step 7: Again, we go back to Step 1, but this time we use the number from Step 4, which is 1...   1 ÷ 16 = 0.0625.


Step 8: We calculate the remainder using the decimal part (0.0625), and it is 1...   0.0625 x 16 = 1.


Step 9: Now, we add this new remainder to the left of our previous remainders, giving us our final answer, 10B.


We keep repeating these steps until we reach 0.00000. Once we do, we have our answer. In this case, we hit 0 in Step 7. We still had to calculate our remainder, but there was no integer to divide by sixteen if we were to make a Step 10. So, 267 in decimal becomes 10B in hexadecimal.


Sample Problem Without Explanation

This time, let us work through the steps of converting a decimal value to a hexadecimal value without all of the explanations, focusing on the math. Try this on a piece of scrap paper to see if you get the same answer. If not, check your work. If you cannot find your error, check with your teacher. 


Problem: Convert 579 to hexadecimal.

579 ÷ 16 = 36.1875

0.1875 x 16 = 3

 3 

36 ÷ 16 = 2.25

0.25 x 16 = 4

 43 

2 ÷ 16 = 0.125

0.125 x 16 = 2

 243 

We have finished because the integer has reached 0.00000. 

579 (decimal) = 243 (hexadecimal)


Practice

Converting Hexadecimal to Decimal

In some ways, converting hexadecimal to decimal may be an easier process to understand than converting decimal to hexadecimal. Just like in decimal, where each value in a number is based on 10 to a power, or in binary, where each value in a number is based on 2 to a power, in hexadecimal, each value in a number is based on 16 to a power. This is illustrated below.  

Let us break down the process of converting a number from hexadecimal to decimal into steps.


Step 1: Write down the hexadecimal number: Start with the hexadecimal number you want to convert.


Step 2: Assign decimal values: Assign decimal values to each hexadecimal digit (A=10, B=11, C=12, D=13, E=14, F=15). 


Step 3: Work digit by digit: Begin from the right side of your hexadecimal number (the ones place). Take the digit you see there and multiply it by 1 (16^0 = 1). Move one place to the left and multiply the next digit by 16 (16^1 = 16). Keep doing this for all the digits in the number (16^2 = 256, 16^3 = 4096, etc.). Add up all these results.


Step 4: Calculate the decimal value: The answer you get after adding up all these results is the decimal equivalent of the hexadecimal number.


Sample Problem With Explanation

Let us follow these steps to convert 35C into decimal. Follow along, making your calculations on a piece of scrap paper.


Step 1: Start by writing down the number you want to convert... 35C.


Step 2: Assign decimal values to any hexadecimal numbers that are greater than 9... 3 5 12


Step 3: Start by multiplying the number on the right by 1 because 16^0 = 1, and the 12 is in the ones place...   12 x 1 = 12.


Step 4: Now, multiply the next number to the left by 16 because 16^1 = 16, and the 5 is in the 16s place...   5 x 16 = 80.


Step 5: Next, multiply the next number to the left by 256 because 16^2 = 256, and the 3 is in the 256s place...   3 x 256 = 768.


Step 6: Our last calculation is to add the values we just calculated together...   768 + 80 + 12 = 860.


Step 7: The sum of our values is the decimal value. So, 35C (hexadecimal) = 860 (decimal).


Sample Problem Without Explanation

This time, let us work through the steps of converting a hexadecimal value to a decimal value without all of the explanations, focusing on the math. Try this on a piece of scrap paper to see if you get the same answer. If not, check your work. If you cannot find your error, check with your teacher. 


Problem: Convert 1A60 to decimal.

1  10  6  0

0 x 1 = 0

6 x 16 = 96

10 x 256 = 2,560

1 x 4,096 = 4,096

 4,096 + 2,560 + 96 + 0 = 6,752 

We have finished because we have converted each value into decimal and then added those values together

1A60 (hexadecimal) = 6,752 (decimal)

   

* An alternative method would be to convert the hexadecimal number into binary and then the binary into decimal. See Converting Hexadecimal to Binary below.

Practice

Converting Hexadecimal to Binary

Converting between hexadecimal and binary is much easier than converting between hexadecimal and decimal. The reason it is so simple is hexadecimal is basically a more efficient way to write binary. One that is much easier for humans to use than tons of 1s and 0s. Simply put, each hexadecimal digit is equal to one binary nibble or four bits. So, 'D' in hexadecimal is the same as ' 1101' in binary, or '13' in decimal. Below is an explanation and some examples.  

Let us break down the process of converting a number from hexadecimal to binary into steps.


Step 1: Write down the hexadecimal number.


Step 2: Assign decimal values: Assign decimal values to each hexadecimal digit (A=10, B=11, C=12, D=13, E=14, F=15).


Step 3: Work from left to right, converting one value at a time. Turn each value into binary - keeping 4 bits for each value. For example, 1 would be 0001, or 6 would be 0110. Keep all the binary numbers in line - leaving space between nibbles for ease of reading and writing.


Step 4: The binary value is the string or 1's and 0's created in step 3.


Sample Problem With Explanation

Let us follow these steps to convert 35C into decimal. Follow along, making your calculations on a piece of scrap paper.


Step 1: Start by writing down the number you want to convert... 35C.


Step 2: Assign decimal values to any hexadecimal numbers that are greater than 9... 3 5 12


Step 3: Start by converting 3 into binary...   0011.   (0 - 8's, 0 - 4's, 1 - 2's, 1 - 1's) 


Step 4: Now, convert 5 into binary, adding it to the right of the previous binary value...   0011 0101.   (0 - 8's, 1 - 4's, 0 - 2's, 1 - 1's) 


Step 5: Finally, convert 12 into binary, adding it to the right of the previous values...   0011 0101 1100.   (1 - 8's, 1 - 4's, 0 - 2's, 0 - 1's) 


Step 6: The sum of our values is the decimal value. So, 35C (hexadecimal) = 0011 0101 1100 (binary).

 

Sample Problem Without Explanation

This time, let us work through the steps of converting a hexadecimal value to a binary value without all of the explanations, focusing on the math. Try this on a piece of scrap paper to see if you get the same answer. If not, check your work. If you cannot find your error, check with your teacher. 


Problem: Convert 1A60 to binary.

1  10  6  0

0001

0001 1010

0001 1010 0110

0001 1010 0110 0000

Just like that, we are finished. We just convert each value into binary and we have our answer. 

1A60 (hexadecimal) = 0001 1010 0110 0000 (binary)


Practice

Converting Binary to Hexadecimal

Converting between binary and hexadecimal is much easier than converting between decimal and hexadecimal. As mentioned previously, the reason it is so simple is hexadecimal is basically a more efficient way to write binary. One that is much easier for humans to use than tons of 1s and 0s. Simply put, each binary nibble or four bits is equal to one hexadecimal digit. So, '1010' in binary is the same as ' A' in hexadecimal, or '10' in decimal. Below is an explanation and some examples.  

Let us break down the process of converting a number from binary to hexadecimal into steps.


Step 1: Write down the binary number - leave space between each nibble (every four digits).


Step 2: Work from left to right, converting one nibble at a time. Turn each value into decimal. For example, 1001 would be 9, or 1110 would be 14. Keep all the decimal numbers in line - leaving space between numbers for ease of converting to hexadecimal values if larger than 9.


Step 3: Assign hexadecimal values: Assign hexadecimal values to each decimal value, if larger than 9 (A=10, B=11, C=12, D=13, E=14, F=15).


Step 4: Write the hexadecimal digits from step 3 with no spaces and you have your hexadecimal value.


Sample Problem With Explanation

Let us follow these steps to convert 1011 0101 0011 into hexadecimal. Follow along, making your calculations on a piece of scrap paper.


Step 1: Start by writing down the number you want to convert... 1011 0101 0011.


Step 2: Assign a decimal value to the first nibble (1011)... 11.   (1 - 8's, 0 - 4's, 1 - 2's, 1 - 1's) 


Step 3: Now, convert the next nibble (0101) into decimal, adding it to the right of the previous decimal value...   11 5.   

              (0 - 8's, 1 - 4's, 0 - 2's, 1 - 1's)


Step 4: Next, convert the final nibble (0011) into decimal, adding it to the right of the previous decimal values...   11 5 3.  

             (0 - 8's, 0 - 4's, 1 - 2's, 1 - 1's)


Step 5: After that, convert any decimal numbers greater than 9 into their hexadecimal equivalent and write the values in order...   B 5 3.  


Step 6: The last step is to remove any spaces between digits. So, 1011 0101 0011 (binary) = B53 (hexadecimal).

 

Sample Problem Without Explanation

This time, let us work through the steps of converting a binary value to a hexadecimal value without all of the explanations, focusing on the math. Try this on a piece of scrap paper to see if you get the same answer. If not, check your work. If you cannot find your error, check with your teacher. 


Problem: Convert  1010 1100 1101 1100 to hexadecimal.

1010 1100 1101 1100

10

10 12

10 12 13

10 12 13 12

A C D C

ACDC

Just like that, we are finished. We just convert each value into decimal, change to the hex letter value if greater than 9, and we have our answer. 

1010 1100 1101 1100 (binary) = ACDC (hexadecimal)


Practice

Hexadecimal, Images, and Color

We already know that hexadecimal is a numbering system that computers use. One of those uses is to describe colors and pictures on a screen. Let us examine the basics of how this works.


Colors in Hexadecimal

Breaking Down Colors: Hexadecimal helps computers break down colors into smaller parts. Imagine you have a magic crayon box with 16 crayons instead of the usual 10. Each crayon is a different shade, and they are numbered 0 to 9 and then A to F. So, you can have colors like 0 (black), 1 (almost black), 2 (a bit darker), 3 (even darker), and so on, up to F (which is the brightest).

Mixing Colors: To create any color, you mix different amounts of these 16 crayons. For example, if you want pink, you might mix a little bit of red (maybe 9) with a lot of white (maybe F). In hexadecimal, this pink could be written as #9FFF.


Pixels in Images

Tiny Color Dots: When you look at a picture or a video on your computer or phone, it is made up of lots and lots of tiny dots called pixels. Each pixel is like a super tiny dot of color.

Color Codes for Pixels: Hexadecimal is used to tell each pixel what color it should be. Instead of saying "Make this pixel red," computers say "Make this pixel #FF0000," which is the code for bright red.

Millions of Pixels: Your screen has millions of pixels, and each one gets a color code in hexadecimal. When they all work together, you see beautiful pictures and videos.


Saving Images

Storing Images: When you save a picture on your computer, it is actually saving all the hexadecimal color codes for each pixel. So, if you send the picture to a friend, their computer knows exactly which colors to use to recreate the image.


Summary

In short, hexadecimal is like the language that computers use to talk about colors and images. It is a way for them to understand and display the stunning visuals you see on your screens, whether it is a beautiful sunset in a photo or the vibrant colors of a video game.

Hexadecimal Image Creator

In the boxes below, add hexadecimal code to turn pixels on or off. Each hexadecimal value (0-F) is equivalent to one nibble or four bits in binary. Once you have a value in the input box for red, green, and blue, the full-color image will appear in the lower grid.  The colors available in this program are red, green, blue, yellow, cyan, magenta, white, and black. Mix different colors to see what different combinations create. Two features have been added, one to allow you to download your image as a PNG file and another to allow you to download your code as a TXT file.