Hexadecimal
Hexadecimal
Lesson Objectives
- Hexadecimal numbers and their representation
- How to convert binary and denary numbers to their hexadecimal equivalents and vice versa
- What are the applications of the hexadecimal number system?
Introduction
- Hexadecimal (or hex) is a system with base 16.
- The 16 digits used in the hexadecimal system and their equivalent value in binary and in denary systems are shown in the table.
- Hexadecimal (or hex) is a system with base 16.
- The 16 digits used in the hexadecimal system and their equivalent value in binary and in denary systems are shown in the table.

Hexadecimal system
- Each nibble (a group of 4 bits) can be represented with 1 digit in a hexadecimal system.
- It is very convenient to write numbers in hex compared to a binary system.
- It is helpful for programmers coding in low-level languages. Instead of 4 bits, it is enough if they type a single character.
- The memory location in a computer is also stated in hexadecimal form. This makes the address more readable.
- Consider a memory address A3F581. If represented in binary, it would be:
- 1010| 0011| 1111| 0101| 0100| 0001
Converting binary to hexadecimal: Step 1

- Starting from right to left, the binary numbers are split into a group of 4 bits.
Converting binary to hexadecimal: Step 2

- If the group has less than 4 bits, zeros are added to the left.
Converting binary to hexadecimal: Step 3

- Each nibble is then converted to its equivalent hexadecimal number.
Converting hexadecimal to binary

- Hexadecimal numbers are converted to binary by finding the 4-bit code.
- Write the nibbles together.
Converting denary to hexadecimal: Step 1

- To convert a denary number to hexadecimal, the number is first converted to binary.
Converting denary to hexadecimal: Steps 2 & 3

- To convert a denary number to hexadecimal, the number is first converted to binary.
- The binary number is converted to a hexadecimal system.
- Ex: Converting the number 14 to hex. The binary form is 1110, which is E in the hexadecimal system.
Converting hexadecimal to denary

- Hexadecimal numbers can be converted to the denary system by using place values.
- The place value is in the powers of 16.
- The value of each digit is multiplied by the place value, and the values are added to find the denary equivalent.
Applications of the hexadecimal system
- A few applications of the hexadecimal system are given:
- Colors
- RGB Colour Model
- Errors
- MAC address
- URL
- Assembly code and machine code
Colors
- Hexadecimal numbers are used to represent colors in various software tools.
- A color is represented in #RRGGBB format. RR, GG, and BB represent the hex number of red, green, and blue colors.
- A pure blue colour is #0000FF, white is #FFFFFFF and black is #0000000.
- Using this method, 256 variants of each color can be made, hence making a total of 256 reds × 256 greens × 256 blues.
- A shade of yellow is represented in hex format as #FEF65B.

RGB Colour Model

- Colors can also be represented using the RGB color model.
- This system is similar to hex system, but each color has a value between 0 to 255.
- Hence, a shade of pink represented in hex format as #FEF65B has an R-value of 254, a G-value of 246, and a B-value of 91.
Errors
- The error message contains a hex number that represents the memory location of the error.
- This information is very useful to programmers.
- The error can be easily rectified by verifying the code in that particular location.
- The process in which the contents of memory are displayed or stored in a storage drive in case of a system crash is called a memory dump.
- Using this information, a programmer can identify the exact location where the error lies.
- Compared to binary, this is easier to understand. The binary form of DEF6B2C3 is: 11011110111101101011001011000011.
- Even though using the hexadecimal system improves the readability of errors, the programmer must have knowledge about the computer architecture to interpret the results.
Mac Addresses
- A media access control address refers to the number on the Internet that uniquely identifies a device on the Internet.
- This is the address of the network interface card (NIC).
- A MAC address is made up of 48 bits, which are shown as a six-group of hexadecimal digits.
NN-NN-NN-DD-DD-DD or NN: NN: NN: DD: DD: DD
- The first half of the address represents the identification number of the manufacturer and the second half of the number represents the serial number of the device. For example: 00: 14: 22: 34: AC: 4F refers to a device made by Dell with a serial number of 34AC4F.
URL

- Hexadecimal values are used to represent web addresses or URL (Uniform Resource Locator). The ASCII codes are used to represent the web address.
- For example: www.google.com becomes: (using the ASCII codes)
- % denotes that hexadecimal values are used.
- Hexadecimal values are used to represent addresses of files and web pages to improve security.
- A user is protected from accessing a fake website when he is asked to use a hexadecimal URL rather than a URL with letters that could be misleading.
Assembly code and machine code
- Machine code and assembly code can be used to refer to the computer memory directly.
- Use of hexadecimal numbers makes low-level language coding easier, faster and reduces errors when compared to the binary system.
- For example: An assembly code instruction ADD is translated to machine code as 0100, which is equivalent to 4 in hexadecimal. It is enough for the programmer to type a single digit ‘4’ when compared to four digits ‘0100’.
Hypertext Markup language (HTML)
- HTML is a markup language widely used in developing web pages.
- It is used to define the attributes of a text, such as color. Tags are used to define objects on a web page.
- For example: The tag <p> is used to define a paragraph. The tag </p> represents its end. The contents between the two are codes.
- Color codes are also used in HTML to define objects.
- For example:
- <p style="color:#FF8000;">Welcome to my website.</p>
- The color code FF8000 represents the orange color. The paragraph looks like this:
- Welcome to my website.
Related Worksheets: