Hexadecimal (#1)

Hexadecimal, or simply known as ‘hex’ in the computing world, is arguably the most widely used number system in firmware programming and control algorithms for various parts of robotic systems. The base used in this number system is 16, which means we calculate the decimal equivalent of hex numbers using powers of 16. {Note: Familiarity with exponents and powers of 16 (at least up to 16^5) is expected from those who wish to understand and practice this number system.} Whenever you see a hex file for some application or software, it is the file having everything written in it in the hexadecimal format.

“Hexadecimal” means 16, meaning “hex” refers to 6 and “decimal” refers to 10, hence the name. We use 16 characters in this number system (in computation, we call the punctuation marks, numbers, letters, symbols, etc. “characters”). We use the decimal numbers 0 to 9, constituting 10 characters, and the remaining six characters are the first six letters of the alphabet (A, B, C, D, E, F).
Therefore, the hexadecimal character set is as follows: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}

In this article, we will see how to convert hex numbers into binary and decimal equivalents.
We will now see the conversion of hex numbers into binary equivalents:

CharacterDecimal ValueBinary Value
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
A101010
B111011
C121100
D131101
E141110
F151111

Let’s take an example of a character to break down the values in the table and justify why 4 bits are required.
1. F is the last character in the hexadecimal system, and its decimal value is 15 (although it is the 16th character, since 0 is the first character).
2. We know from the article about binary numbers how to convert 15 into binary. It comes to be 1111.
3. Therefore, the convention is set such that each character, whether they need 4 bits to describe their decimal equivalent or not, must be written in 4 bits (also called a nibble or half a byte).
4. As we know, 8 bits is one byte. So the smallest possible number is  {(00000000)_2} = 0_{10} , and the largest possible number is  {(11111111)_2 = 255_{10}} . (Verify this for yourself).
5. If we break the above bytes into nibbles, then it will look like this:  \text{(0000 0000)$_2$} = 00_{16} = 0_{10} and  \text{(1111 1111)$_2$} = FF_{16} = 255_{10} . You can refer to the table above and compare the values to confirm that these are true.

Now, we will understand how to convert hexadecimal numbers into decimal numbers:

Example 1: Convert  {(F3D4)_{16}} into a decimal number.

  1.  \text {Just like binary system, we will convert the number by using powers of 16 from right to the left.}
  2.  {(4 \times {16^0})+(D \times {16^1})+(3 \times {16^2})+(F \times {16^3})}
  3.  {= (4 \times 1)+(13 \times 16)+(3 \times 256)+(15 \times 4096)}
  4.  {= 4+208+768+61440}
  5.  {= 62420_{10}}

Example 2: Convert  {(EE44)_{16}} into a decimal number.

  1.  {(4 \times {16^0})+(4 \times {16^1})+(E \times {16^2})+(E \times {16^3})}
  2.  {= (4 \times 1)+(4 \times 16)+(14 \times 256)+(14 \times 4096)}
  3.  {= 4+64+3584+57344}
  4.  {= 60996_{10}}

Example 3: Convert  {(46656)_{10}} into a hex number.

  1. Divide 46656 by 16.
  2. Record the remainder (it will be between 0 and 15, including both).
  3. Assign the remainder value its respective hex equivalent (refer to the table above).
  4. Take the quotient (the result of the division) and divide it by 16 again.
  5. Repeat until the quotient is 0.
StepDivisionQuotientRemainderHex symbol for remainder
146656 ÷ 16291600
22916 ÷ 1618244
3182 ÷ 161166
411 ÷ 16011B

Now, read the remainders from the bottom to the top (from the last remainder to the first).
Bottom to top: $$ {(46656)_{10} = (B640)_{16}} $$

Example 4: Convert  {(64020)_{10}} into a hex number.

  1. Divide 64020 by 16.
  2. Record the remainder (it will be between 0 and 15, including both).
  3. Assign the remainder value its respective hex equivalent (refer to the table above).
  4. Take the quotient (the result of the division) and divide it by 16 again.
  5. Repeat until the quotient is 0.
StepDivisionQuotientRemainderHex symbol for remainder
164020 ÷ 16400144
24001 ÷ 1625011
3250 ÷ 161510A
415 ÷ 16015F

Now, read the remainders from the bottom to the top (from the last remainder to the first).
Bottom to top: $$ {(64020)_{10} = (FA14)_{16}} $$

By using this, we can apply various logical operations in motor control and robotics and also in data science and low-level programming languages like C and assembly. With these conversion techniques under your belt (whether transforming F3D4 into decimal or converting 64020 into a hex number), you now have a fundamental tool used in firmware development, debugging, and embedded systems. Practice these conversions until they become second nature. In the next part, we will explore this concept further and its detailed applications. Until then, keep learning and stay curious!


Discover more from universeunlocks.in

Subscribe to get the latest posts sent to your email.

Leave a Reply