Data Representation

Data Representation

Sep 21, 2023·

5 min read

A major stumbling block many beginners encounter when attempting to learn assembly language is the common use of the binary and hexadecimal numbering systems.

Review of the Decimal System

You've been using the decimal numbering system for so long that you probably take it for granted.

In a decimal positional numbering system, each digit appearing to the left of the decimal point represents a value between 0 and 9 times an increasing power of 10

Binary Number System

Binary numbers are what defines the core of a computer. Abit within a computer is either on or off. A bit has either electricity turned on or off.

It is important to understand that in binary, each column has a value two times the column to its right and there are only two digits in the base which happen to be 0 and 1.

In decimal, base 10, say we have the number 15 which means (1x10)+(5x1) therefore 5 is the number times 1 and 1 is that number times 10.

Binary works in a similar fashion however we are now referring to base 2 That same number in binary is 1111. To illustrate

1111
8s4s2s1s

(8x1)+(4x1)+(2x1)+(1x1)

Binary numbers are important because using them instead of the decimal system simplifies the design of computers and related technologies.

Hexadecimal Number System

This exciting number system is called hexadecimal. The reason why we use this number system is that in x86 Assembly it is much easier to express binary number representations in hexadecimal than it is in any other numbering system.

Hexadecimal is similar to every other number system except in hexadecimal, each column has a value of 16 times the value of the column to its right. The fun part about hexadecimal is that not only do we have 0-9 we have A-F and therefore 16 different symbols.

Let's look at a simple table to see how hexadecimal compares to decimal.

DecimalOctalHexBinary
0000
1111
22210
33311
444100
555101
666110
777111
81081000
91191001
1012A1010
1113B1011
1214C1100
1315D1101
1416E1110
1517F1111
16201010000
17211110001
18221210010
19231310011
20241410100
21251510101
22261610110
23271710111
24301811000
25311911001
26321A11010
27331B11011
28341C11100
29351D11101
30361E11110
31371F11111
324020100000
334121100001
............

Ok, I see the smoke coming out of your ears but it is ok! In decimal, everything is dealt with in the power of 10. Let's take the number 42 and examine it in decimal:

2 x 10^0 = 2
4 x 10^1 = 40

Remeber 10 to the 0 power is 1 and 10 to thr 1st power is 10. therefore, 2+40 =42

Here comes the fun stuff

If we understand that decimal is a base 10 number system, we can create a simple formula where b represents the base, In this case, b = 10

(2 b ^ 0) + (4 b ^ 1)

(2 10 ^ 0) + (4 10 ^ 1) = 42

I hexadecimal, everything is dealt with in the power of 26. Therefore 42 in decimal is 2A in hexadecimal:

10 * 16 ^ 0 = 10

2 * 16 ^ 1 = 32

Keep in mind 10 decimal is equal to A hexadecimal and 2 decimal is equal to 2 hexadecimal. In our formula above when we deal with A, B, C, D, E or F we need to convert them to their decimal equivalent.

Let's take another example of F5 hexadecimal. This would be as follows:

5 x 16^0 = 5

15 x 16^1=240

5 + 240 = 245 decimal => F5 hexadecimal

It is fundamental that you understand what is going on here in order to proceed any further.

Credits: