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 the 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 it could: 4 + 60 + 700. Even more complicated? Yes: 4*1 + 6*10 + 7*100. Could this number look more scientific? The answer is yes again: 4*100 + 6*101 + 7*102. What does it actually mean? Why do we use exactly these numbers: 100, 101 and 102 ? Why is it always about the number 10? Because we use ten different digits (0, 1, 2, ... 8, 9). In other words, we use base-10 number system, i.e. decimal number system.
BINARY NUMBER SYSTEM
What would happen if only two digits are used- 0 and 1? Or if we don’t not know how to determine whether something is 3 or 5 times greater than something else? Or if we are restricted when comparing two sizes, i.e. if we can only state that something exists (1) or does not 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. Bear in mind that all this is about mathematics with only two digits- 0 and 1, i.e. base-2 number system (binary number system).
It is obviously the same number represented in two different number systems. The only difference between these two representations is the number of digits necessary for writing a number. One digit (2) is used to write the number 2 in decimal system, whereas two digits (1 and 0) are used to write it 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 for strictly controlled laboratory conditions, the most complicated 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 reasons are electrical noises and something called the ‘real working environment’ (unpredictable changes of power supply voltage, temperature changes, tolerance to values of built-in components etc.). Imagine a computer which operates upon decimal numbers by treating them in the following way: 0=0V, 1=5V, 2=10V, 3=15V, 4=20V...9=45V. Did anybody say batteries? A far simpler solution is a 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 voltage’, respectively. It is about logic zero (0) and logic one (1) which electronics perfectly cope with and easily performs all those endlessly complex mathematical operations. Obviously, the electronics we are talking about applies 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 NUMBER SYSTEM
At the very beginning of computer development it was realized that people had many difficulties in handling binary numbers. For this reason, a new number system, using 16 different symbols was established. It is called hexadecimal number system and consists of the 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 about 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 decimal system, whereas in hexadecimal system it is represented by only one digit F. It is the largest 1-digit number in 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. Don’t forget that computers use 8-digit binary numbers. By chance?
BCD CODE
BCD code is a binary code for decimal numbers only (
Binary-Coded Decimal). It is used to enable electronic circuits to communicate either with peripherals using decimal number system or within ‘their own world’ using binary system. It consists of 4-digit binary numbers which represent the first ten digits (0, 1, 2, 3 ... 8, 9). Even though four digits can give in total of 16 possible combinations, the BCD code normally uses only the first ten.
NUMBER SYSTEM CONVERSION
Binary number system is most commonly used, decimal system is most understandable, while hexadecimal system is somewhere between them. Therefore, it is very important to learn how to convert numbers from one number system to another, i.e. how to turn a sequence of zeros and ones into understandable values.
BINARY TO DECIMAL NUMBER CONVERSION
Digits in a binary number have different values depending on the position they have in that number. Additionally, each position can contain either 1 or 0 and its value may be easily determined by counting its position from the right. To make the conversion of a binary number to decimal it is necessary to multiply values with the corresponding digits (0 or1) and add all the results. The magic of binary to decimal number conversion works...You doubt? Look at the example below:
It should be noted that in order to represent decimal numbers from 0 to 3, you need to use only two binary digits. For larger numbers, extra binary digits must be used. Thus, in order to represent decimal numbers from 0 to 7 you need three binary digits, for the numbers from 0 to 15 you need four digits etc. Simply put, the largest binary number consisting of n digits is obtained when the base 2 is raised by n. The result should then be subtracted by 1. For example, if n=4: 2
^{4} - 1 = 16 - 1 = 15 Accordingly, by using 4 binary digits it is possible to represent decimal numbers from 0 to 15, which amounts to 16 different values in total.
HEXADECIMAL TO DECIMAL NUMBER CONVERSION
In order to make the conversion of a hexadecimal number to decimal, each hexadecimal digit should be multiplied with the number 16 raised by its position value. For example:
HEXADECIMAL TO BINARY NUMBER CONVERSION
It is not necessary to perform any calculations in order to convert hexadecimal numbers to binary. Hexadecimal digits are simply replaced by appropriate binary digits. Since the maximum hexadecimal digit is equivalent to the decimal number 15, we need to use four binary digits to represent one hexadecimal digit. For example:
A comparative table below contains the values of numbers 0-255 in three different number systems. This is probably the easiest way to understand the common logic applied to all the systems.
MARKING NUMBERS
Hexadecimal number system is along with binary and decimal systems considered to be the most important number system for us. It is easy to make conversion of any hexadecimal number to binary and it is also easy to remember it. However, these conversions may cause confusion. 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! Accordingly, in order to avoid misunderstanding, different prefixes and suffixes are directly added to the numbers. The prefix $ or 0x as well as the suffix h marks the numbers in hexadecimal system. For example, the hexadecimal number 10AF may look as $10AF, 0x10AF or 10AFh. Similarly, binary numbers usually get the prefix % or 0b. If a number has neither suffix nor prefix it is considered decimal. Unfortunately, this way of marking numbers is not standardized, thus depends on concrete application.
BIT
Theory says 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 decimal number system in which digits of a number do not have the same value (for example digits in the decimal number 444 are the same, but have different values), the ‘significance’ of bit depends on its position in the binary number. Since there is no point talking about units, tens etc. in binary numbers, their digits are referred to as the zero bit (rightmost bit), first bit (second from the right) etc. In addition, since the binary system uses two digits only (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 just means that its value is represented in decimal system. Simply put, we have got so much accustomed to the usage of decimal numbers that such expressions became common. It would be correct to say for example, ‘the value of the sixth bit of any binary number is equivalent to the decimal number 64’. But we are human and old habits die hard...Besides, how would it sound ‘number one-one-zeroone- zero...’?
BYTE
A byte consists of eight bits grouped together. If a bit is a digit, it is logical that 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 greatest 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 schematic comprise only a few different elements called logic circuits or logic gates?