Digital Logic Design: Number System
Digital Logic Design: Number System
Digital Logic Design: Number System
Number System
NANA PROF. K DIAWUO
Learning Objectives
•Number systems: Binary, octal, and hexa-decimal number
systems, binary arithmetic.
•Comprehension
•Application
•Application
• Decimal numbers
• DRC is known as 9’s-complement
• RXC is known as 10’s-complement
• Most computers support a variety of data types.
• Numeric
• Integer
• Signed- Sign and magnitude - one bit, usually the leftmost bit, represents the sign
of the number (0 for +, 1 for -), the remaining bits specify the magnitude of the
number. So n bits can represent values from -(2(n-1) -1) to +(2(n-1) -1) There are two
representations for 0, +0 and -0. Numbers are negated by inverting the sign bit.
• One's complement - n-bit numbers can represent values from -(2 (n-1)-1) to +(2(n-1) -
1) [n one's represent -0 and n 0's represent +0].
• The negative of a value is obtained by inverting each bit.
• Two's complement - n-bit numbers can represent values from -2n-1 to +(2n-1 -1)
[there is a unique representation of 0, n 0 bits] the representation of a negative
value is obtained by adding 2n, the modulus, to the negative value. Note that this
is done only for negative values. Positive values have the same representation as
the corresponding natural number. With this representation negative values
always correspond to bit patterns that have a 1 in the MSB position. In general,
the value represented by an n-bit pattern in a two's complement system is:
• -2(n -1) ´a(n-1) +a(n -2) ´2 (n-2) + ··· + a1 ´21 +a0 ´20
• Floating Point
The effect of a sliding (i.e. floating) number point can be obtained by
including an exponent to specify the logical position of the number point
within the bit pattern. This representation would require 4 components, the
exponent, the sign of the exponent, the bits that comprise the number, and
the sign of the number. This representation will be examined more closely
later.
• Non-numeric
• Character data
One byte of storage is used to contain the representation of one character. The
most common representation is an encoding scheme called ASCII (American
Standard Code for Information Interchange). IBM mainframes use a scheme
called EBCDIC (Extended Binary Coded Decimal Interchange Code).
• Boolean
• Items that can only take on two values (true or false, 0 or non-zero) can be
represented as a single bit or as a single byte or word.
• String data
• Collections of adjacent bytes can hold individual characters and correspond to
a character string. Often a prefix byte or word holds a count indicating the
length of the string. Alternatively, the final byte could contain a null character
to identify the end of the string.
• Collections of adjacent bits within one or more words may be used as bit
strings. Auxiliary information must be used to specify the length of each bit
1’s Complement Representation
•The most significant bit (MSD) represents the sign If MSD
is a ‘0’
The number is positive
Remaining (n-1) bits directly indicate the magnitude
0000110 --> + 6
0000000 --> + 0
1111111 --> - 0
1111001 --> - 6
1000000 --> - 63
128
127
100
+0
-0
-100
-127
-128
Convert binary to decimals
• Now let's look at the number 110.112
• Since the binary system is a base-2 number system, we can make this
formula more specific:
• DIGIT * 2 POSITION #
Fours Twos Ones Halves Fourths
22 21 20 2-1 2-2
1 1 0 . 1 1
Using our formula, we see that the first digit of our binary number
represents the value 1 * 22 or 4 and the second digit represents the
value 1 * 21 or 2. Continuing this pattern, we can express the number
110.11 as follows:
2
1*22 = 1*4 = 4.
1*21 = 1*2 = 2.
0*20 = 0*1 = 0.
1*2-1 = 1*.5 = 0.5
1*2-2 = 1*.25 = + 0.25
6.75
0.5*2 = 1.0
Answer:
0.011
We can also organize this conversion in
table form as we did with the previous one.
2.11 is greater than 10, so we write a 1 in the quotient, copy the divisor below the dividend,
1 10|11 10 1
and subtract using the borrow method.
3.Since we have no more digits in our dividend, but we still have a remainder, our answer
must include a fraction. To finish our problem we need to mark the radix point and append a 1. 10|11.0 10 1
zero to the dividend.
4.Now we bring down the extra zero and write it beside our remainder. Then we check to see
1. 10|11.0 10
if this new number is greater than or equal to our divisor. Notice we ignore the radix point in
10
our comparison.
5.10 equals the divisor 10, so we write a 1 in the quotient, copy the divisor below the
1.1 10|11.0 10
dividend, and subtract. This completes our division because we have no more digits in the
10 10 0
dividend and no remainder.
Binary multiplication uses the same technique as decimal multiplication.
In fact, binary multiplication is much easier because each digit we multiply
by is either zero or one.
Consider the simple problem of multiplying 110 by 10 . 2 2
0111 (7)
3. Next, we add the negative value we computed
+ 1110 +(-1)
to 0111 . This gives us a result of 10101 .
2 2
10101 (?)
4. Notice that our addition caused an overflow
bit. Whenever we have an overflow bit in 1's 0101
complement, we add this bit to our sum to get + 1
the correct answer. If there is no overflow bit, 0110 (6)
then we leave the sum as it is.
0111 (7)
5. This gives us a final answer of 0110 (or 6 ).
2 10
- 0001 - (1)
0110 (6)
Now let's look at an example where our problem
does not generate an overflow bit. We will
subtract 710 from 110 using 1's complement.
0001 (1)
1. First, we state our problem in binary.
- 0111 - (7)
0001 (1)
2. Next, we convert 0111 to its negative equivalent and add
2
+ 1000 +(-7)
this to 0001 .
2
1001 (?)
b. 01100 - 01010
2 2
c. 00100 - 00101
2 2
d. 01001 - 01011
2 2
e. 00011 - 01100
2 2
f. 00110 - 01001
1.Convert your answers from question 5 to decimal to check
your work. Remember that your answers are in 1's
complement representation. [Answer]
2.For each of the following problems convert the subtrahend
to an 8-bit 1's complement representation and subtract.
Leave your answer in binary. [Answer]
a. 01111111 - 78
2 10
b.00110010 - 123
2 10
c. 01001001 - 111
2 10
d.00000111 - 35
2 10
Two's Complement
Representing a signed number with 2's complement is done by
adding 1 to the 1's complement representation of the number. To
illustrate, let's look at the same example we used for 1's complement.
How can we represent the number -5 in 2's complement using 4-
10
bits?
First, we write the positive value of the number in
0101 (+5)
binary.
2.Next, we reverse each bit to get the 1's
1010
complement.
3.Last, we add 1 to the number. 1011 (-5)
• To the right is a table of 4-bit binary numbers in 2's Binary Decimal
complement notation. Comparing these values 0111 +7
with our 1's complement table, we see that both 0110 +6
0101 +5
representations use the most significant bit to 0100 +4
represent the sign. We also notice that we only 0011 +3
have one way to represent 0 in 2's complement. 0010 +2
This is an advantage because it simplifies 0001 +1
representation of signed numbers. As with 1's 0000 +0
1111 -1
complement, only negative values need to be 1110 -2
complemented in 2's complement. The positive 1101 -3
values are the same as the normal binary numbers. 1100 -4
You should verify for yourself that the negative 1011 -5
1010 -6
values are correct by using the steps below to 1001 -7
produce this table. 1000 -8
•Here is a quick summary of how to find the 2's
complement representation of any decimal number x.
Notice the first three steps are the same as 1's
complement.
• If x is positive, simply convert x to binary.
• If x is negative, write the positive value of x in binary
• Reverse each bit.
• Add 1 to the complemented number.
Subtraction with Two's
Complement
Now let's consider how we would solve our problem of subtracting 1 10
This 32-bit pattern can be written in short hand form using 8 hex digits: