Computers use binary code which is made up of all “ones and zeroes”. But why? Why don’t PCs and smartphones work in the decimal system that we are all used to? The answer can be found in the technology as well as in the sheer elegance of the binary system. It is a lot simpler than many people think. Can you perform calculations with binary code too?
The hexadecimal system
Whereas the decimal system and its ten digits is deeply embedded in our daily lives, computer science and data processing rely heavily on the binary system, or binary code. The binary system makes it possible to represent complex situations with just two states: 0 and 1. However, large binary numbers quickly become messy. This is where the hexadecimal system can be of help. Information that’s expressed using eight digits in the binary system can be expressed using just two hexadecimal numbers.
Black Friday Deals
Our best deals of the year. Offers end after Cyber Monday.
Don't miss out!
What is the hexadecimal system?
The word hexadecimal is made up of the terms hexa and decimal. Hexa comes from the Greek and means “six”, whereas decem is the Latin word for “ten”. The hexadecimal system is thus a place-value system that represents numbers using the base of 16. That means that the hexadecimal system uses 16 different digits. In other words, there are 16 possible digits, in contrast to the two in the binary system (0 and 1) and the ten in the decimal system (0 to 9). But what’s the purpose of the system?
What is the hexadecimal system used for?
The hexadecimal system is used in computer technology and makes large numbers and long bit sequences more readable. They’re grouped into sections of four bits and then converted into hexadecimal numbers. The result is that a long sequence of ones and zeros get turned into shorter hexadecimal numbers, which can in turn be divided into groups of two or four. Hexadecimal numbers are thus a more compact way to represent bit sequences. The system is used for, for example, source and destination addresses in Internet Protocols (IPs), in ASCII codes, or for describing color codes in web design with the stylesheet language CSS.
Do you need a new website? The website builder MyWebsite offers professional design templates in modern color combinations.
Hexadecimal system: How to write it
As mentioned above, the hexadecimal system uses 16 digits. This is where we run into a potential problem. In our traditional way of writing numbers we use the decimal numbers 10, 11, 12, 13, 14, and 15, which consist of two symbols put together. So if you were to use the number 10 in hexadecimal notation, it would be unclear what you mean.
To avoid this problem, the letters A through F are used to represent the numbers ten through 15 in the hexadecimal system. So in total, the numbers 0 through 9 and A through F are used to represent the equivalents of binary numbers and decimal numbers. There are various notations available for distinguishing hexadecimal numbers from decimal numbers:
- 73_{16}
- 73_{hex}
- 73h
- 73H
- 73H
- 0x73
- $73
- #73
- "73
- X’73’
The prefix 0x and the suffix h are especially common in programming, and the dollar prefix $ is frequently used in certain processor families in assembly language.
The relationship between hexadecimal numbers and binary numbers
When it comes to representing complex states, bit sequences and binary strings can get very long. In our daily use of the decimal system, we use groups of three digits to make big numbers like millions, billions, and trillions more readable. The same goes for digital systems. To make bit sequences like 1111010111001111_{2} easier to read, they’re usually divided into groups of four. So our example would look like this: 1111 0101 1100 1111_{2}. It gets even easier to read when binary numbers are converted into the hexadecimal system.
Since sixteen is the fourth power of two (2^{4}), there’s a direct relationship between the numbers two and sixteen: one hexadecimal digit corresponds to four binary digits. That means that you can represent four digits from a binary number with a single hexadecimal digit. This makes the conversion between binary and hexadecimal numbers relatively easy, and big binary numbers can be written in the hexadecimal system with fewer digits.
In computer engineering, one binary digit corresponds to one bit. A byte consists of eight bits, and a half byte (also referred to as a nibble consists of 4 bits. This means that a nibble can be represented with one hexadecimal digit and a full byte with two hexadecimal digits.
Hexadecimal table for conversion into decimal and binary numbers
The hexadecimal system is more complex than the binary and decimal systems and is often used in connection with memory addresses. Binary numbers are divided into groups of four bits, and each group of bits has a value between “0000” and “1111”. This results in 16 different number combinations from 0 to 15. Note that “0” is also a valid digit.
Decimal number | 4 bit binary number | Hexadecimal number |
0 | 0000 | 0 |
1 | 0001 | 1 |
2 | 0010 | 2 |
3 | 0011 | 3 |
4 | 0100 | 4 |
5 | 0101 | 5 |
6 | 0110 | 6 |
7 | 0111 | 7 |
8 | 1000 | 8 |
9 | 1001 | 9 |
10 | 1010 | A |
11 | 1011 | B |
12 | 1100 | C |
13 | 1101 | D |
14 | 1110 | E |
15 | 1111 | F |
16 | 0001 0000 | 10 (1+0) |
17 | 0001 0001 | 11 (1+1) |
18 | 0001 0010 | 12 (1+2) |
19 | 0001 0011 | 13 (1+3) |
20 | 0001 0100 | 14 (1+4) |
According to the hexadecimal conversion table, the binary number sequence 1111 0101 1100 1111_{2} from before will look like this in the hexadecimal system: F5CF. This number is much easier to read than the long sequence of bits. The hexadecimal system can be used to write digital code with fewer digits and thus less chance of making mistakes. Converting hexadecimal numbers back into binary numbers can be done just as easily, using the same hexadecimal table above.
In order to make it clear that the number is a hexadecimal number, we can write it as follows: F5CF_{16},_{}$F5CF, or #F5CF. The last notation, also called a hash value, is used for digital color coding, since designers and developers use hex colors in web design. Hex colors are represented with a six-place combination of numbers and letters determined by its mixture of red, green, and blue (RGB). #000000 stands for black and #FFFFFF for white.
Counting with hexadecimal numbers
Now you know how to convert binary numbers into hexadecimal numbers. If you’re working with more than four binary digits, simply start over or continue with the next set of four bits. With two hexadecimal digits you can count to FF, which corresponds to the decimal number 255.
Adding additional hexadecimal digits in order to convert a binary number into a hexadecimal number is very easy when you have four, eight, twelve, or sixteen digits. But you can also add “0” or “00” to the left of the highest bit even if the number of binary digits is no longer a multiple of four. For example, 110010110110011_{2} is a fourteen-bit long binary number, which is too big for three hexadecimal digits but too small for four.
The solution is to add additional zeros to the left end of the number until you have a full set of four-bit binary numbers. In our example that would look as follows: 00110010110110011_{2}.
Summary
The biggest advantage of the hexadecimal system is the compactness of its numbers, since fewer digits are required to represent a number than in binary or decimal notation. This is thanks to its base of sixteen. And it’s relatively easy to convert binary numbers into hexadecimal numbers and vice versa.
You offer services, run an online store, or are working on a website for the project you’re really passionate about? Make a good impression with your own email address and domain and benefit from high security for your sensitive data.