## 1.2 Numbers, numbers, numbers...

Mathematics is such a good science! Everything is so logical... The whole universe can be described with ten digits only. But, does it really have to be like that? Do we need exactly ten digits? Of course not, it is only a matter of habit. Remember the lessons from school. For example, what does the number 764 mean: four units, six tens and seven hundreds. It's as simple as that! Could it be described in a more complicated way? Of course: 4 + 60 + 700. Even more complicated? Definitely: 4*1 + 6*10 + 7*100. Could this number look more scientific? The answer is yes again: 4*10^{0} + 6*10^{1} + 7*10^{2}. What does it actually mean? Why do we use exactly these numbers: 10^{0}, 10^{1} and 10^{2} ? Why is it always about the number 10? The answer is because we use ten different digits (0, 1, 2, ... 8, 9). In other words, we use the base-10 number system, i.e. decimal numeric system.

### BINARY NUMERIC SYSTEM

What would happen if only two digits were used- 0 and 1? Or if we didn't not know how to determine whether something is 3 or 5 times greater than something else? Or if we were restricted when comparing two sizes, i.e. if we could only state that something exists (1) or doesn't exist (0)? The answer is 'nothing special', we would keep on using numbers in the same way as we do now, but they would look a bit different. For example: 11011010. How many pages of a book does the number 11011010 include? In order to learn that, you just have to follow the same logic as in the previous example, but in reverse order. As you can see here, it's all based on only two digits- 0 and 1, i.e. on the base-2 numeric system (binary numeric system).

It is clearly the same number represented in two different numeric systems. The only difference between these two formats is the number of digits they consist of. One digit (2) is used for writing number 2 in decimal system, whereas two digits (1 and 0) are used for its writing in binary system. Do you now agree that there are 10 groups of people? Welcome to the world of binary arithmetic! Do you have any idea where it is used?
Except in strictly controlled laboratory conditions, even the most complex electronic circuits cannot accurately determine the difference between two sizes (two voltage values, for example) if they are too small (lower than several volts). The reason for it lies in the noise and something known as a ‘real working environment’ (unpredictable changes of power supply voltage, temperature change, tolerance to values of built-in components etc.). Imagine a computer which operates upon decimal numbers by interpreting them as follows: 0=0V, 1=5V, 2=10V, 3=15V, 4=20V...9=45V.
Did anybody say batteries?
A far simpler solution is the binary logic where 0 indicates that there is no voltage and 1 indicates that there is a voltage. It is easier to write 0 or 1 instead of full sentences ‘there is no voltage’ or ‘there is a voltage’, respectively. It is about a logic zero (0) and a logic one (1) which electronics perfectly copes with, and easily performs all those endlessly complex mathematical operations. Obviously, the electronics we are talking about applied mathematics in which all the numbers are represented by two digits only and where it is only important to know whether there is a voltage or not. Of course, we are talking about digital electronics.

### HEXADECIMAL NUMERIC SYSTEM

At the very beginning of the computer development there were many problems when working with binary numbers. For this reason, a new numeric system, using 16 different symbols was established and called a hexadecimal numeric system. It is comprised of ten digits we are used to (0, 1, 2, 3,... 9) and six letters of alphabet A, B, C, D, E and F. You probably wonder what’s the purpose of this seemingly bizarre combination? Just look how perfectly it fits the story about binary numbers and you will understand.

The largest number that can be represented by 4 binary digits is the number 1111. It corresponds to the number 15 in a decimal system, whereas it is represented by letter F in hexadecimal system. It is the largest 1-digit number in the hexadecimal system. Do you see how skillfully it is used? The largest number written with eight binary digits is at the same time the largest 2-digit hexadecimal number. Remember that computers use 8-digit binary numbers. Coincidence?

### BCD CODE

A BCD code is a binary code for decimal numbers only (

**B**inary-**C**oded **D**ecimal). It consists of 4-digit binary numbers representing the first ten digits (0, 1, 2, 3 ... 8, 9). Even though four bits can give 16 possible combinations in total, the BCD code makes advantage of the first ten only.

### NUMBER SYSTEM CONVERSION

The binary numeric system is the most commonly used, the decimal system is the most understandable, while the hexadecimal system is somewhere in the middle. Therefore, it is very important to learn how to convert numbers from one numeric system to another, i.e. how to turn a sequence of zeros and ones into understandable values.

#### BINARY TO DECIMAL NUMBER CONVERSION

Same digits in a binary number have different values depending on their position in that number. Each position may contain either 1 or 0 and its value can be easily determined by counting its position from the right. To perform a binary to decimal number conversion it is necessary to multiply digits (0 or 1) with their position value (2

^{0}, 2

^{1}, 2

^{2}, 2

^{3} etc.) and add all the results. The magic of binary to decimal number conversion works... Look at the example below:

In order for decimal numbers from 0 to 3 to be represented, you need only two binary digits. For larger numbers, extra binary digits must be used. Thus, in order for the decimal numbers from 0 to 7 to be represented, three binary digits are required, for numbers from 0 to 15, four digits etc. Simply put, the largest binary number consisting of n digits is obtained when the base 2 is raised by n and the respective result is subtracted by 1. For example, if n=4:
2

^{4} - 1 = 16 - 1 = 15
Accordingly, 4 binary digits enable you to represent decimal numbers from 0 to 15, which amounts to 16 different values in total.

#### HEXADECIMAL TO DECIMAL NUMBER CONVERSION

To perform a hexadecimal to decimal number conversion, each hexadecimal digit should be multiplied with 16 raised by its position value and after that, the obtained results should be added. For example:

#### HEXADECIMAL TO BINARY NUMBER CONVERSION

It is not necessary to perform any calculations to convert hexadecimal numbers to binary. Hexadecimal digits are simply replaced by appropriate binary digits. Since the maximum value of a hexadecimal digit is equivalent to decimal number 15, it is necessary to use four binary digits to represent one hexadecimal digit. For example:

A comparative table on the left shows the values of numbers 0-255 represented in three different number systems. This is probably the easiest way to understand the common logic applied to all numeric systems.

### MARKING NUMBERS

The hexadecimal numeric system is, along with binary and decimal numeric systems, considered the most important for us. It is easy to convert any hexadecimal number to binary. It is also easy to remember it. However, such conversions may confuse us. For example, what does the sentence ‘It is necessary to count up 110 products on the assembly line’ actually mean? Depending on whether it is about binary, decimal or hexadecimal system, the result could be 6, 110 or 272 products, respectively. To avoid such and similar situations, different prefixes and suffixes are directly added to the numbers. Prefixes $ and 0x mark hexadecimal numbers. For example, hexadecimal number 10AF looks either as $10AF or 0x10AF. Similarly, binary numbers usually get the prefix %. If a number has neither suffix nor prefix it is considered decimal. Unfortunately, this way of marking numbers is not standardized, yet depends on specific application.

### BIT

In theory, a bit is the basic unit of information... Let’s forget this for a moment and take a look at what it is in practice. The answer is- nothing special- a bit is just a binary digit. Similar to the decimal numeric system where the same digits of a number do not have the same value (for example, digits in decimal number 444), the ‘significance’ of bits depends on their positions in the binary number. Unlike the decimal numeric system, binary digits are not referred to as units, tens etc, but zero bit (rightmost bit), first bit (second from the right) etc. Since the binary system uses only two different digits (0 and 1), the value of one bit can be either 0 or 1.
Don’t be confused if you come across a bit having value 4, 16 or 64. It means that its value is represented in the decimal system. We are simply so much accustomed to the usage of decimal numbers that such expressions are very common. It would be correct to say for example, ‘the value of the sixth bit of any binary number is equivalent to decimal number 64’. But we are human and old habits die hard... Besides, how would it sound ‘number one-one-zero-one-zero...’?

### BYTE

A byte consists of eight bits grouped together. If a bit is a digit, then bytes represent numbers. All mathematical operations can be performed upon them, like upon common decimal numbers. Similar to digits of any number, byte digits do not have the same significance either. The largest value has the leftmost bit called the most significant bit (MSB). The rightmost bit has the least value and is therefore called the least significant bit (LSB). Since eight zeros and ones of one byte can be combined in 256 different ways, the largest decimal number which can be represented by one byte is 255 (one combination represents a zero).
A nibble is referred to as half a byte. Depending on which half of the register we are talking about (left or right), there are ‘high’ and ‘low’ nibbles, respectively.

*Have you ever wondered what electronics within digital integrated circuits, microcontrollers or processors look like? What do circuits performing complicated mathematical operations and making decisions look like? Do you know that their seemingly complicated schematics comprise only a few different components called logic circuits or logic gates?*