Introduction to PLC controllers on-line FREE!
APPENDIX D Numerical systems
People were always difficult to except the
fact that something is different from themselves or their way of thinking.
It is probably one of the reasons why numerical systems other than decimal
are hard to understand. Still, whether we like it or not, reality is quite
different. Decimal system used in everyday life is by far less used than
binary code, which is the working basis for millions of computers across
Decimal numerical system is defined with its
basis 10 and decimal positioning from right to left, and it consists of
digits 0,1,2,3,4,5,6,7,8,9. This means that the
rightmost digit is multiplied by 1 in total sum, next digit to it is
multiplied by 10, next one by 100, etc.
Operations of addition,
subtraction, division and multiplication in decimal numerical system are
well known, so we will not detail these.
Binary numerical system is quite different
from the decimal that we got used to in common life. Its basis is 2 and
each digit can have one of two values, “1” or “0”. Binary numerical system
is used for computers and microcontrollers, because it is much easier for
processing than decimal. Usually, binary number consists of 8, 16 or 32
binary digits. Origins of this division are irrelevant for this course, so
we will just take it for granted.
We still need to understand the logic of binary numerical system, i.e. how to get the decimal value of a number out of the sequence consisting of ones and zeros. This procedure is called conversion of binary number to decimal value.
As it can be seen, conversion of binary number to decimal value is done by totaling the sum on the right. Depending on the position in the binary number, digits carry different “weight” multiplied by themselves, and totaling them all gives us an understandable decimal number.
Let’s further assume that there are marbles in each of the drawers, 2 in the first, 4 in the second, 7 in the third and 3 in the fourth. Let the person opening the drawers also use the binary system. Under these conditions, question would be “How many marbles are there in 01?”, and the answer would be “There are 100 marbles in 01!” Notice that both question and answer are clear, although we did not use common terminology. Further, notice that two digits are sufficient for decimal numbers from 0 to 3, and that all values greater than 3 require additional binary digits. Thus, for 0 ~ 7 range, three digits are sufficient, four digits cover the range 0 ~ 15, etc. Simply put, the greatest decimal number that can be represented with n binary digits is 2 raised to power n, decreased by one.
Arithmetical operations that exist in decimal numerical system also apply
in binary system. In this chapter, we will cover only addition and
subtraction, for simplicity sake.
We can do the check by converting these numbers to decimal system and
adding them. Value of the first number is 10, value of the second is 9 and
19 as result, which means that operation was done correctly. Problem occurs
when the result is greater than can be represented with given number of
binary digits. There are various solutions, one of them being expanding
the number of binary digits like in the example below.
Subtraction works on the
same principles as addition does. Two zeros give zero in result, as do two
ones, while subtraction of one from zero requires borrowing one from the
higher position in binary number. Example:
Hexadecimal numerical system has number 16
for basis. Therefore, there are 16 different digits used in this system.
These are “0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F”. Letters A, B,
C, D, E and F represent values 10, 11, 12, 13, 14, 15 and are used for the
sake of easier notation. As with binary numerical system, we can apply the
same formula here for determining the greatest decimal number that can be
represented with a given number of hexadecimal digits.
Addition works similar to two previous numerical systems.
Binary numerical system
remains the most commonly used, decimal system the most intelligible,
while hexadecimal is somewhere in between. It’s simple conversion to
binary system makes it, besides binary and decimal, the most important
numerical system to us.
© C o p y r i g h t 2 0 0 3. m i k r o E l e k t r o n i k a. All Rights Reserved. For any comments contact webmaster.