Word for the day: NUMBER SYSTEMS
Although we take pride in the fact that the number "0" (Zero) was given to the world by Aryabhata, one of the most well known Indian astronomer & mathematician, none of us would want to score this number in any of our assignments ! Be it our exams, game or even at work. Each one of us struggle to have the magical 100% in anything and everything that we do in our life. The feeling of being number one (1) is incomparable.
It is quite interesting (and probably contradictory) that the latest digital electronic devices, which have become integral part of our life in one way or other, does not understand anything except zero (0) and one (1). They do not like 100% or any other "decimal" numbers. These 0s and 1s form the most fundamental method of representing anything: be it audio, video, PLC program, CNC machine code. Welcome BINARY NUMBERING system, on which we will throw some light this week. There are three other widely used "intermediate" numbering systems – HEXADECIMAL, BCD & OCTAL – which we will touch upon in the end.
Binary – an old Latin word generally meaning two conditions or numbers – system is a method of representing any number, character in combination of 0s and 1s referred to the base of 2 (also called Base-2 system). The regular numbers we write follow decimal system (also called Base-10 system). Recall our earlier newsletter on DIGITAL systems, where we mentioned about two voltage states indicating ON or 1 and OFF or 0 condition and also that the computers can only understand 0s and 1s to perform any task.
Let us take go to our good old school days. Consider the following numbers for example:
4 = 22
(= 2 x 2) 8 = 23
(= 2 x 2 x 2) 32 =
25
(= 2 x 2 x 2 x 2 x 2)
9 = 23 + 1 (= 2 x 2 x 2 + 1) 67 = 26 + 3 (= 2 x 2 x 2 x 2 x 2 x 2 + 3)
1 = 20
As you can see, each number can be represented as a "power" of two, adding or subtracting an additional number. Let us now re-write the above numbers to obtain same result. From mathematics fundamentals, we definitely know that anything multiplied by zero results in zero.
4 = 1 x 22 + 0 x 21 + 0 x 20 = 4 + 0 + 0 = 4
8 = 1 x 23 + 0 x 22 + 0 x 21 + 0 x 20 = 8 + 0 + 0 + 0 = 8
9 = 1 x 23 + 0 x 22 + 0 x 21 + 1 x 20 = 8 + 0 + 0 + 1 = 9
32 = 1 x 25 + 0 x 24 + 0 x 23 + 0 x 22 + 0 x 21 + 0 x 20 =
32 + 0 + 0 + 0 + 0 = 32
67 = 1 x 26 + 0 x 25 + 0 x 24 + 0 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = 64 + 0 + 0 + 0 + 0 + 2 + 1 = 67
1 = 1 x 20 = 1
All the above number has 2 as its multiplier base, with its power varying and multiplier being either 0 or 1. Now by grouping only the numbers marked red, the BINARY equivalent of corresponding decimal numbers can be obtained.
The number of 0 and 1 increases as the decimal number increases. Each of these 0 and 1 are called "bits." To provide uniformity for understanding and calculation the number of bits will be fixed to certain numbers. Any unused bit will be filled with zero. 4, 8, 16, 32, 64 and 128 (256 is also used but mostly in supercomputing) bits are the most used sizes and using this standard we can re-represent the numbers as shown in table-2.
Independent of number of bits, it is interesting to note that as 1 move towards left, its equivalent decimal value increases. And when 1 moves towards right, the equivalent decimal value decreases. Therefore, in the binary format, the LEFT most bit is called MOST SIGNIFICANT BIT (MSB) and RIGHT most bit is called LEAST SIGNIFICANT BIT (LSB). For example, for decimal 8, the MSB is 1 and LSB is 0 and for 67, MSB is 0 and LSB is 1. To check your understanding of this basic binary system, fill the bits for numbers shown in the table-3. Remember to fill all the bits and mark the MSB & LSB. Any number can be represented to base-2 using simple formula, 2n-1, where "n" is the number of bits.
17 | 11 | 5 |
As we probably know that any electronic device does not handle numbers alone. They also process alphabets and other characters. So how are they represented in the "bit" format? A special standard called ASCII (American Standard Code for Information Interchange) consisting of 7 bits (27 – 1 = 127 bits) was formed during 1960s and is still used in all the binary circuits. Few examples of ASCII representation are given in the table below. Complete ASCII table is attached in e-mail message. Explore it yourself.
A | 1 | 0 | 0 | 0 | 0 | 0 | 1 | a | 1 | 1 | 0 | 0 | 0 | 0 | 1 |
? | 0 | 1 | 1 | 1 | 1 | 1 | 1 | / | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
On an interesting note, if you have to represent "1st Rank" in binary format, here is how it looks. (Remember letters "a" & "A" will have different ASCII codes). Aren't we all happy not to communicate in binary language?!
1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
s | 1 | 1 | 1 | 0 | 0 | 1 | 1 |
t | 1 | 1 | 1 | 0 | 1 | 0 | 0 |
R | 1 | 0 | 1 | 0 | 0 | 1 | 0 |
A | 1 | 0 | 0 | 0 | 0 | 0 | 1 |
N | 1 | 0 | 0 | 1 | 1 | 1 | 0 |
K | 1 | 0 | 0 | 1 | 0 | 1 | 1 |
As you can see, to represent such a simple word, binary system has used 49 bits. In any electronic device, each bit "occupies" space (call it memory) and as the number of bits grow, space required also increases. And, as the number of bits increase, time required to read them and display will also increases. Binary method of representation is not limited only to numbers or letters. Electrical system, Programmable Logic Controllers and many more day-to-day machine control elements also use them extensively.
As an example, let us consider an 8-point DIGITAL (discrete) 230V AC input module of a programmable logic controller. External components like limit switches, proximity sensors, and push buttons will be "wired" to this module. These input components either close or open one or more contacts. When closed, it gives 230V AC input at the module. Refer Figure-1. Inside the input-module, 230V will generally energize a small relay. A low-voltage relay (usually 5V DC) signal is connected thru NO (Normally Open) contact of the relay. This signal will be "stored" as bit 1 in the memory. When the 230V AC turns off, relay de-energizes and the bit will be changed to 0. On the other hand, in an output module the 5V DC may energize a relay which in turn will turn on the required output.
In CNC control systems, all the codes used for programming the cutting path of a tool for example, will be stored in the machine memory as a group of many bits.
Logic circuits, gates, digital counters, timers are other common example where binary system is commonly used.
We will be introducing a made- -easy series on Programmable Logic Controllers, Basic Electronics in due course of time. You will enjoy and learn the fundamentals more easily.
Coming back, as we saw from last few illustrations, as the quantity of word or character to be represented increases or as input-output to be handled expands, numbers of bits increase considerably. This not only occupies more "storage space," but also makes the reading process very difficult. Just imagine how many bits will be necessary to represent your home address. You will be surely amazed and confused at the same time.
So, to make the representation more compact and less complex, HEXADECIMAL (commonly called HEX code) system was introduced. Hexadecimal is a Greek word which means number 16. In binary system, base-2 multiplication system is used to represent any decimal number. Base-16 will be used in hexadecimal system to represent the same number. Before elaborating little deeper, let us look at the table below to understand what the differences between these two number systems are. As you can see, to represent numbers, hexadecimal system uses one number or one letter for EVERY FOUR BITS of binary system. From a representation point this means easier understanding for the user and less space is required to store the same information. The last hexadecimal digit, F represents 15 in decimal system. How do we represent a number that occupies 8 bits in binary system?
DECIMAL | BINARY | HEXADECIMAL |
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 |
Any number that needs to be represented by MORE THAN four bits will be separated and "grouped" as four bits and its hexadecimal equivalent will be obtained. Let us revisit number 32 and understand how it is represented in hexadecimal format.
32 = 0 0 1 0 0 0 0 = 0 x 27 + 0 x 26 + 1 x 25 + 0 x 24 + 0 x 23 + 0 x 22 + 0 x 21 + 0 x 20 = 32
In binary system, eight bits are necessary to represent this number. When separated and grouped as four bits, it looks like this:
32 = 0 0 1 0 0 0 0 0
Now reading from the table beside, we can write its equivalent HEXADECIMAL code as 20. As the number bits increases, as per binary system, they have to be split into groups of four bits. Any unavailable bit should be substituted with zero to suit four bit grouping. Now let us convert a decimal number 64640 occupying 16 bits to its hexadecimal equivalent.
64640 = 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 = 1 x 215 + 1 x 214 + 1 x 213 + 1 x 212 + 1 x 211 + 1 x 210 + 0 x 29 + 0 x 28 + 1 x 27 + 0 x 26 + 0 x 25 + 0 x 24 + 0 x 23 + 0 x 22 + 0 x 21 + 0 x 20 = 64640
Now let us create four bit groups starting from MSB: 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 Reading from the table above, the hexadecimal equivalent will be FC80. It is quite evident that representing becomes easier with hexadecimal format for large and complex numbers.
Hexadecimal system can also be used to represent words, special characters similar to binary system. But explaining these concepts, at this point, will be beyond the scope of this newsletter.
To check your understanding, write hexadecimal code for simple numbers in the table below.
17 | 11 | 18 |
BCD or Binary Coded Decimal is another commonly used format available for representing numbers (and any characters). Certain rotary encoders (they are called BCD encoders), CNC machine control systems, display devices, traffic signal system use BCD.
In BCD, like binary system, each number (digit) is represented by its bit format, BUT separately. To understand let us revisit the numbers 32 & 64640. We already know how to represent them in binary and hex format. To represent in BCD, each digit will be identified by binary digit separately.
3 = 0 0 1 1 2 = 0 0 1 0 Combine them to obtain BCD code 32 = 0 0 1 1 0 0 1 0
6 = 0 1 1 0 4 = 0 1 0 0 6 = 0 1 1 0 4 = 0 1 0 0 0 = 0 0 0 0
Combine them to obtain BCD code 64640 = 0 1 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 0
Another most commonly used number representation is octal format. Octal means eight in Greek work (recollect Octagon representing eight sides) and uses base-8 for converting decimal numbers. By now you all must be able to play with 0s and 1s. Now let us revisit the numbers 32 and 67 to understand octal numbering system. Instead of using 2 as multiplier, we will be use 8 for octal system.
32 = 4 x 81 + 0 x 80 67 = 1 x 82 + 0 x 81 + 3 x 80
So the octal equivalent of 32 will be 40 and 67 will be 103. As you can see, octal format actually uses same decimals for representation, but slightly differently. Octal systems are also widely used in programmable logic controllers, variable speed drives, old NC machines and some special control systems.
To check your understanding, write octal code for simple numbers in the table below.
76 | 55 | 88 |
Tip for the newsletter
On your personal computer, if you have calculator software, you can experiment with numbers in different systems. By default, it will be in decimal format. Enter the desired number and select Oct (Octal) or Bin (Binary) or Hex (Hexadecimal) to see the respective types
NOTE: Independent of any type of number representation system used the final format that any electronic component understands is BINARY. So, intermediate converters take care of this conversion process, elaborating on which is definitely beyond the scope, at this point, of newsletter. And, when a decimal like 3.1415927 (equivalent of 22/7 or π) needs to be stored as binary numbers, electronic circuit perform special calculations.
1 comment:
I am the kind of guy who passions to seek fresh stuff. Currently I'm fabricating my personal photovoltaic panels. I am doing it all by myself without the aid of my men. I'm utilizing the internet as the only way to acheive that. I discovered a very brilliant site which explains how to contruct pv panels and wind generators. The website explains all the steps required to constructing pv panels.
I am not sure bout how accurate the information given there is. If some people over here who had xp with these things can have a peak and give your feedback in the thread it will be awesome and I'd really appreciate it, cauze I truly passion [URL=http://solar-panel-construction.com]solar panel construction[/URL].
Thanks for reading this. You people are great.
Post a Comment