DIGITAL
Number System
A number system consists of a set of symbols, known as Digits. The combination of these digits makes a number which has two parts integer and fraction, separated by a Radix Point (.). The radix or Base indicates the total number in the number system. Many number systems are in use in digital technology. The most common are the decimal, binary, octal, and hexadecimal systems. The decimal number system is the most familiar to us because it is a tool that we use every day. (1) Decimal (2) Binary (3) Octal (4) Hexadecimal
Decimal System
The decimal system is composed of 10 symbols or numerals. These 10 symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Using these symbols as digits of a number, we can express any quantity. The decimal system is also called the base-10 system because it has 10 digits. 103 = 1000
Most Significant Digit
102 = 100
101 = 10
100 = 1
.
Decimal point
10 1 = 0.1
10 2 = 0.01
INTEGER
FRACTION
Even though the decimal system has only 10 symbols, any number of any magnitude can be expressed by using our system of positional weighting. Examples of Decimal Numbers: (3.14)10, (52)10, (1024)10, (64000)10, etc.
Binary System
Computers are not as smart as humans are (or not yet), it's easy to make an electronic machine with two states: on and off, or 1 and 0. Computers use binary system. In the binary system, there are only two symbols or possible digit values, 0 and 1. Hence, the Base or Radix of this number system is 2. This, base 2 number system can be used to represent any quantity that can be represented in decimal or other base system. To understand binary numbers, begin by recalling elementary school math. When we first learned about numbers, we were taught that, in the decimal system, things are organized into columns: H T U 1 7 9 Such that "H" is the hundreds column, "T" is the tens column, and "U" is the units column. So the number "179" is 1 hundreds plus 7 tens plus 9 ones. Years later, we learned that the ones column meant 100, the tens column meant 101, the hundreds column 102 and so on, such that the number 179 is really {(1102) + (7101) + (9100)}. The decimal system uses the digits 0 9 to represent numbers. 102 1 101 7 100 9
The binary system works under the exact same principles as the decimal system, only it operates in base 2 rather than base 10. In other words, instead of columns being
1 Dr.Gulam Rabbani
SEM I 102 23 = 8
Most Significant Bit
they are
22 21 = 0.5
21 22 = 0.25
20 23 = 0.125
Least Significant Bit
INTEGER
FRACTION
The bit on the far right side is called the Least Significant Bit (LSB), because it stands in the place of the lowest weight (the one's place). The bit on the far left side is called the Most Significant Bit (MSB), because it stands in the place of the highest weight (the one hundred twenty-eight's place). Remember, a bit value of "1" means that the respective place weight gets added to the total value, and a bit value of "0" means that the respective place weight does not get added to the total value. The Binary counting sequence is shown in the table 23 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 22 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 21 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 20 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
In digital systems the information that is being processed is usually presented in binary form. Binary quantities can be represented by any device that has only two operating states or possible conditions, e.g. a switch is only open or closed. Let an open switch represent binary 0 and a closed switch represent binary 1. Thus we can represent any binary number by using series of switches. The following voltage levels generally represent HIGH (1) or LOW (0) Logic. Binary 1: Any voltage between 2V to 5V Binary 0: Any voltage between 0V to 0.8V
2 Dr.Gulam Rabbani
SEM I
DIGITAL
Not used: Voltage between 0.8V to 2V in 5 Volt CMOS and TTL Logic, this may cause error in a digital circuit. Today's digital circuits work at 1.8 volts also, so this statement may not hold true for all logic circuits. Volts
5V Logic 1 2V Not Used 0.8V Logic 0 0V
1 3.8V
A significant difference between digital and analog systems is that in digital systems, the exact voltage value is not important; e.g. a voltage of 3.6V means the same as a voltage of 4.3V. In analog systems, the exact voltage value is important. The binary number system is the most important one in digital systems. The decimal system is important because it is universally used to represent quantities outside a digital system. This means that there will be situations where decimal values have to be converted to binary values before they are entered into the digital system. Binary-To-Decimal Conversion Any binary number can be converted to its decimal equivalent simply by summing together the weights of the various positions in the binary number which contain a 1. Binary (11011)2 4 1 2 +1 23+0 22+121+120 Result Also Binary (1110101)2 6 5 12 +12 +124+023+122+021+120 Result Decimal =64+32+16+0+4+0+1 (117)10 Decimal =16+8+0+2+1 (27)10
SEM I
DIGITAL
Decimal-To-Binary Conversion
There are 2 methods:
A simple example is illustrated in the following table: Decimal (25)10 Result Binary = 16 + 8 + 0 + 0 + 1 = 24 + 23 + 0 + 0 + 20 =(11001)2
This method is suitable for small numbers. As the value of number increases the possibility of error in conversion also increases.
4 Dr.Gulam Rabbani
DIGITAL
This method uses repeated division of the integer decimal number by base of the number system in which conversion is desired till zero quotient is obtained. And the remainders are collected in reverse order. For decimal to binary conversion the given decimal number will be successively divided by 2. Convert (25)10 to binary
Division
25/2 12/2 6/2 3/2 1/2 Result
Quotient + Remainder
= 12+ remainder of 1 = 6 + remainder of 0 = 3 + remainder of 0 = 1 + remainder of 1 = 0 + remainder of 1 (25)10
Remainder (Binary)
1 (Least Significant Bit) 0 0 1 1 (Most Significant Bit) = (11001)2
SATRT
DIVIDE BY BASE (2)
Is Q = 0?
No
Yes
Collect Remainders in Reverse Order to get Desired Binary Number
END Repeated Multiplication (Double Dabble) Method to Convert Fractional Decimal Numbers to binary
5 Dr.Gulam Rabbani
SEM I
DIGITAL
This method uses repeated multiplication of the fractional decimal number (or fractional part of the decimal number) by base of the number system in which conversion is desired till product obtained is zero. And the carries are collected in forward order (same as obtained). Many a times the product does not become zero whatever times we multiply the given fraction. In such cases the multiplication is stopped when repetition of carry takes place taking care that the last carry is one (1). For decimal to binary conversion the decimal number will be successively multiplied by 2. Convert (0.625)10 to binary Multiplication 0.625 2 0.25 2 0.5 2 Result Convert (0.4)10 to binary Product & Carry = 1.250 &carry is 1 = 0.5 &carry is 0 = 1.0 &carry is 1 (0.625)10 Carry (Binary) 1 (Most Significant Bit) 0 1 (Least Significant Bit) = (0.101)2
Multiplication Product & Carry Carry (Binary) 0.4 2 = 0.8 &carry is 0 0 (Most Significant Bit) 0.8 2 = 1.6 &carry is 0 1 0.6 2 = 1.2 &carry is 0 1 0.2 2 = 0.4 &carry is 0 0 0.4 2 = 0.8 &carry is 0 0 0.8 2 = 1.6 &carry is 0 1 (Least Significant Bit) Result (0.4)10 = (0.011001)2 In the above example the product will never give fractional part as zero. Hence after going up to five or six places after binary point and taking care that the last carry is (1) the product is terminated. In such cases the conversion will give approximate value instead of exact value.
Binary Addition
34 + 28 62 We begin by adding 4 + 8 = 12. Since 12 is greater than 10, a one is put into the 10's column (carried), and a 2 is recorded in the unit's column of the sum. Next, add {(3 + 2) + 1} (the one is from the carry) = 6 which is put in the 10's column of the sum. Thus, the answer is 62. Binary addition works on the same principle, but the numerals are different. Begin with one-bit 0 0 1 binary addition: + 0 + 1 + 0 0 1 1 Consider the addition of decimal numbers: 1+1 carries us into the next column. In decimal form, 1 + 1 = 2, in binary, any value higher than 1 requires a column to the left (as any value greater than 9 in decimal notation requires). The decimal number "2" is written in binary notation as "10" (1 2 1) + (0 20). Record the 0 in the units column, and carry the 1 to the twos column to get an answer of "10." In our vertical notation, 1 + 1 10 Remember the following rules for Binary Addition
0+0=0
6 Dr.Gulam Rabbani
SEM I
DIGITAL
0+1=1 1+0=1 1 + 1 = 10 {Here the sum is zero with a carry one (1) moving into next more significant column}
1010 + 1111
Step one: Column 20: 0 + 1 = 1. Record the 1. Temporary Result: 1; Carry: 0 Step two: Column 21: 1 + 1 = 10. Record the 0 carry the 1. Temporary Result: 01; Carry: 1 Step three: Column 22: 1 + 0 = 1 Add 1 from carry: 1 + 1 = 10. Record the 0 carry the 1. Temporary Result: 001; Carry: 1 Step four: Column 23: 1 + 1 = 10. Add 1 from carry: 10 + 1 = 11. Record the 11. Final result: 11001 Alternately: 11 (Carry) 1010 + 1111 11001
Binary Multiplication
Multiplication in the binary system works the same way as in the decimal system. The rules for binary multiplication are as follows:
Note that since binary operates in base 2, the multiplication rules we need to remember are those that involve 0 and 1 only. Two numbers A and B can be multiplied by partial products: for each digit in B, the product of that digit in A is calculated and written on a new line, shifted leftward so that its rightmost digit lines up with the digit in B that was used. The sum of all these partial products gives the final result. Since there are only two digits in binary, there are only two possible outcomes of each partial multiplication: If the digit in B is 0, the partial product is also 0
7 Dr.Gulam Rabbani
SEM I
DIGITAL
If the digit in B is 1, the partial product is equal to A As an example of binary multiplication we have 101 times 11, 101 11 First we multiply 101 by 1, which produces 101. Then we put a 0 as a placeholder as we would in decimal multiplication, and multiply 101 by 1, which produces 101. 101 11 101 1010 the 0 here is the placeholder The next step, as with decimal multiplication, is to add. The results from our previous step indicates that we must add 101 and 1010, the sum of which is 1111. 101 x11 101 1010 1111 Another example, the binary numbers 1011 and 1010 are multiplied as follows: 1 0 1 1 (A) 1 0 1 0 (B) -------------0 0 0 0 Corresponds to a zero in B + 1 0 1 1 0 Corresponds to a one in B + 0 0 0 0 0 0 Corresponds to a zero in B + 1 0 1 1 0 0 0 Corresponds to a one in B ------------------=1101110 (1 0 1 1)2 (1 0 1 0)2 = (1 1 0 1 1 1 0)2 Binary numbers can also be multiplied with bits after a binary point: 1 0 1.1 0 1 (A) (5.625 in decimal) 1 1 0.0 1 (B) (6.25 in decimal) ---------------1.0 1 1 0 1 Corresponds to a one in B + 0 0.0 0 0 0 0 Corresponds to a zero in B + 0 0 0.0 0 0 0 0 + 1 0 1 1.0 1 0 0 0 + 1 0 1 1 0.1 0 0 0 0 ------------------------= 1 0 0 0 1 1.0 0 1 0 1 (35.15625 in decimal) (1 0 1.1 0 1)2 (1 1 0.0 1)2 = (1 0 0 0 1 1.0 0 1 0 1)2 Note that multiplying by two is extremely easy. To multiply by two, just add a 0 on the LSB end.
Binary Subtraction
Subtraction is generally simpler than addition since only two numbers are involved and the upper value representation is greater than the lower value representation. The problem of "borrow" is similar in binary subtraction to that in decimal. The rules for binary subtraction are as follows:
8 Dr.Gulam Rabbani
SEM I
DIGITAL
0 0=0 1 0=1 1 1=0 0 1 = 1, and borrow 1 from the next more significant bit
Let's first look at an easy example. 111 10 101 Note that the difference is the same if this was decimal subtraction. Also similar to decimal subtraction is the concept of "borrowing." Watch as "borrowing" occurs when a larger digit, say 8, is subtracted from a smaller digit, say 5, as shown below in decimal subtraction. 35 8 27 For 10 minus 1, 1 is borrowed from the "tens" column for use in the "ones" column, leaving the "tens" column with only 2. The following examples show "borrowing" in binary subtraction. 10 100 1010 1 10 110 1 10 100 The subtraction in binary is pretty much the same way as in base 10. You subtract digit by digit starting on the right side. If the subtraction cannot be made (for example, you cannot subtract 1 from 0), you must then "borrow", just as you do in base 10 subtraction. But when you borrow a "one" from the 4's digit, it turns into two 2's. This borrowing by two's (rather than 10's) is what makes it quite different from base 10 subtraction. Perhaps an example will explain it clearly: 10101 1011 Starting on the right, 1 1 = 0, so the rightmost digit in the answer is 0. Moving left, we cannot subtract the 1 from the 0 (in the 2's position), so we borrow one from the 4's position giving us 2 in 2's position. Now 2 1 = 1 so that there is a 1 in the 2's position of the answer. Moving left 0 0 = 0 (remember we already borrowed the 1 in the 4's position of the top number) so 0 is the answer digit in the 4's position. Moving left, we cannot subtract 1 from 0 so we borrow a 1 from the 16's position giving us 2 in the 8's position. 2 1 = 1 so the answer is 1010. It would look like this when you are done 10101 1011 --------1010 Just to check, in base 10 this would be (21)10 (11)10 = (10)10, yes it checks! The following example {(10110)2 (1100)2} demonstrates the four rules of binary subtraction: 1 0110 1100 1010 Rule 1 (0)2 (0)2 = (0)2 Rule 2 (1)2 (0)2 = (1)2
9 Dr.Gulam Rabbani
Rule 3 (1)2 (1)2 = (0)2 Rule 4 (0)2 (1)2 = (1)2 with a barrow (1)2
SEM I
DIGITAL
Rule 4 presents a different situation because you cannot subtract 1 from 0. Since you cannot subtract 1 from 0 and have a positive difference, you must borrow the 1 from the next higher order column.
ONES COMPLEMENT
The inverse of a number is known as its complement. To complement a number in base 10, you subtract digit from 9 and it is known as 9s complement. Likewise in base 2 (i.e. binary), the complement is obtained by subtracting each bit from1 and it is known as 1's complement. e.g. the complement of 10011101011 is 01100010100. 1s complement is the negative equivalent of given binary number. Thus, using complement method the subtraction converts to addition. All you have to do to obtain 1s complement of given binary number, in fact, is replace 0's with 1's and 1's with 0's. The rules for ones complement subtraction are as under:
1. 2. 3.
SEM I
DIGITAL
Step 5: The addition generates an end around carry. Thus the result is positive and correct result is obtained by adding this end around carry to LSB column. Hence the correct result is (100)2. Now let's look at an example where an overflow bit is not generated. Let us subtract (6)10 from (2)10 using 1's complement. Step 1: Write the binary equivalent of both the numbers, (10)2 and (110)2. Step 2: Make both the numbers of equal bits by placing a zero to the left of (10)2, So that it becomes (010)2. Step 3: Obtain the 1s complement of the number to be subtracted, it is (001)2. Step 4: Add this complemented number to the number from which subtraction is desired. 0 10 010 110 100 +001 1s Complement 011 1s Complement of (011)2 is (100)2 Step 5: The addition does not generate any end around carry. Thus the result is negative and in complement form, the correct result is obtained by taking the 1s complement of the result (011)2 and placing a negative sign before it. Hence the correct result is (100)2.
TWOS COMPLEMENT
Another way to subtract binary numbers is 2s complement subtraction. The 2s complement of a binary number is its 1s complement plus one. e.g. the 2s complement of (11101011)2 is (00010100)2 + (1)2 = (00010101)2 ; also 2s complement of (101000)2 is (010111)2 + (1)2 = (011000)2; yet another example 2s complement of (101100)2 is (010011)2 + (1)2 = (010100)2. From the above examples it is clear that 2s complement of a given number can easily be obtained by retaining the bits from LSB up to first 1 towards MSB and after first 1 replacing the zeros by 1 and 1 by zero till MSB is reached. As in example 2 the first four LSBs (1000)2 have been retained and last two bits have been complemented as in 1s complement, hence obtaining the 2s complement as (011000)2. 2s complement is the negative equivalent of given binary number. Thus, using complement method the subtraction converts to addition. All you have to do to obtain 2s complement of given binary number, in fact, retain the bits from LSB towards MSB till first 1 appears for remaining bits replace 0's with 1's and 1's with 0's. The rules for twos complement subtraction are as under:
SEM I
DIGITAL
5. If an end around carry results the result is positive and if no end around carry is there the result is negative. In both the situations the results requires correction. (a) When the result is positive a carry is generated from the last column (MSB), called as end around carry. To correct the result discard (remove) this end around carry. (b) When the result is negative the carry is not generated from the last column (MSB) and the result is in 2s complement form. To get the correct result take 2s complement of the result and place a negative sign to the left. Let us perform subtraction (10110011)2 (101101)2 using 2s complement method: Step 1: Add two leading zeros to the number to be subtracted so as to make equal bits in both the numbers. Thus the number (101101)2 becomes (00101101)2. Step 2: Obtain the 1s complement of the number to be subtracted, i.e. of the number (00101101)2 which is (11010010)2. Step 3: Add 1 to the 1s complemented number so as to get 2s complement of the given number, thus (11010010)2 + (1)2 = (11010011)2. Step 4: Now add this 2s complement number (11010011)2 to the number from which subtraction is desired i.e. (10110011)2. 10110011 00101101 10000110
2s Complement
Step 5: The addition generates an end around carry. Thus the result is positive and correct result is obtained by discarding this end around carry. Hence the correct result is (10000110)2. Let us perform subtraction (1101)2 (11010)2 using 2s complement method: Step 1: Add one leading zero to the number (1101)2 so as to make equal bits in both the numbers. Thus the number (1101)2 becomes (01101)2 . Step 2: Obtain the 1s complement of the number to be subtracted, i.e. of the number (11010)2 which is (00101)2. Step 3: Add 1 to the 1s complemented number so as to get 2s complement of the given number, thus (00101)2 + (1)2 = (00110)2. Step 4: Now add this 2s complement number (00110)2 to the number from which subtraction is desired i.e. (01101)2 .
2s Complement
01101 01101 11010 + 00110 1s 0 1 1 0 1 Complement of (10011)2 is (01100)2 1 1 1 0 0 adding 1 to it we get 2s complement; (01100)2 + (1)2 = (01101)2.
12 Dr.Gulam Rabbani
SEM I
DIGITAL
Step 5: The addition does not generate any end around carry. Thus the result is negative and in 2s complement form, the correct result is obtained by taking the 2s complement of the result and placing a negative sign before it. Hence the correct result is ( 01101)2.
Binary Division
Binary division is the repeated process of subtraction, just as in decimal division. Adopt the following steps while performing binary subtraction. 1. Align leftmost digits in dividend and divisor. 2. First, find the smallest part of dividend that is greater than or equal to the divisor. If the divisor has N bits, we start by checking the first N bits of the dividend starting from MSB. If that portion of dividend is greater than equal to the divisor then subtract the divisor from that portion of the dividend and place 1 in the quotient field. 3. When the remainder is greater than or equal to the divisor, write a 1 in the quotient and subtract. 4. When the remainder is less than the divisor, write a 0 in the quotient and add another digit from the dividend. 5. If all the digits of the dividend have been considered and there is still a remainder, mark a radix point in the dividend and add on a zero. Remember that some fractions do not have an (1011)2 will terminate. exact representation in binary, so not all division problems (11)2 = (11)2; R = (10)2 (101010)2 (110)2 = (111)2 For Example: 11 = (3)10 1 1 1 = (7)10 11 0 1 1 0
)1
0 1 0 1 0 = (42)10 = (6)10 1 0 0 1 1 1 0 0 1 1 0 1 1 0
101 ) 1 0 1 1 (11)10 1 1
= (3)10 1 0 1 11 1 0 (Remainder)
1 0 1 0 0 0
SEM I
DIGITAL
162 = 256
161 = 16
160 = 1
.
Hex point
16 1 = 1/16
162 = 1/256
INTEGER
FRACTION
Let's start counting and representing numbers in hexadecimal. Now remember, we have 16 symbols (numbers) to count with, 0-9 and A F. Let's say we just start counting: 0...1...2...3...4...5...6...7...8...9...A...B...C...D...E...F Remember, A = 10; B = 11; C = 12; D = 13; E = 14; and F = 15 Oops! We're out of numbers. Now, what do we do? Well, let's name our next number "16". Then, let's create another column to count with and call it the "16s" column. Then, let's go on counting as shown in the table (1.1). The thing to note in the Hexadecimal Hexadecimal Decimal Decimal table (1.1) is that we are 16s 1s 16s 1s multiplying each hexadecimal symbol by its 16 1 0 24 1 8 respective column or 17 1 1 25 1 9 placeholder value. For example, to represent the 18 1 2 26 1 A number "27" in hex we 19 1 3 27 1 B take the hex symbol "B" which equals 11 and 20 1 4 28 1 C multiply it by the column
21 1 14 Dr.Gulam Rabbani1 22 23 1 5 6 7 29 30 31 1 1 1 D E F
SEM I
DIGITAL
value which is 1. We do the same for the column to the left multiplying 1 by its placeholder value of 16. Thus, we have 11 + 16 = 27. If we kept on counting, we could count to 255 with just a 16s and a 1s column before we would run out of numbers and have to start our 256s column. Let's skip ahead in our counting and look at that- run out of numbers at 255 and have to start a 256s column. Here are the last 10 numbers counting up to 255 and the first 10 numbers after we create a 256s column (Table 1.2):
Decimal Hexadecimal 16s 1s Decimal Hexadecimal 256s 16s 1s
246 247 248 249 250 251 252 253 254 255
F F F F F F F F F F
6 7 8 9 A B C D E F
256 257 258 259 260 261 262 263 264 265
1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9
15 Dr.Gulam Rabbani
SEM I
DIGITAL
16 Dr.Gulam Rabbani
SEM I
DIGITAL
17 Dr.Gulam Rabbani
SEM I
DIGITAL
1. Number System:
(15) [1 credits]
Number System: Decimal, Binary, Hexadecimal Number Systems and their inter conversions , Binary arithmetic (addition, subtraction, multiplication and division), 1s and 2s compliment method for binary subtraction, Hexadecimal addition and subtraction, 8421 (BCD) code, BCD addition and subtraction, Gray code, Excess-3 code,
18 Dr.Gulam Rabbani