Digital Logic Design: Number System

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 48

Digital Logic Design

Number System
NANA PROF. K DIAWUO
Learning Objectives
•Number systems: Binary, octal, and hexa-decimal number
systems, binary arithmetic.
•Comprehension

1.Explain how a number with one radix is converted into a number


with another radix.

2.Summarize the advantages of using different number systems.

3.Interpret the arithmetic operations of binary numbers.

4.Explain the usefulness of different coding schemes.

•Application

1.Convert a given number from one system to an equivalent


number in another system.
•Comprehension

1.Explain how a number with one radix is converted into


a number with another radix.

2.Summarize the advantages of using different number


systems.

3.Interpret the arithmetic operations of binary numbers.

4.Explain the usefulness of different coding schemes.

•Application

1.Convert a given number from one system to an


equivalent number in another system.
Numbers
•We use numbers
– to communicate
– to perform tasks
– to quantify
– to measure
• Numbers have become symbols of the present era
• Many consider what is not expressible in terms of
numbers is not worth knowing
Number Systems in use
•Symbolic number system
•uses Roman numerals (I = 1, V = 5, X = 10, L = 50,
• C = 100, D = 500 and M = 1000)

•Weighted position system


• Decimal system is the most commonly
used
• Base used is 10
• Binary numbers are most extensively
used
• Binary system uses radix 2
• Octal system uses radix 8
• Hexa-decimal system uses radix 16
Representing signed numbers
• Diminished Radix Complement (DRC) or (r-1) - complement
• Radix Complement (RXC) or r-complement Binary numbers

• DRC is known as 1’s-complement


• RXC is known as -complement

• 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

• Unsigned - each bit corresponds to a power of 2 an n-bit number can represent


values from 0 to (2n -1)

• 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

• 2.1.1.2 Binary Coded Decimal (BCD)


• Each decimal digit (0 - 9) is encoded in 4 bits (0000 - 1001) 4-
bit values in the range 1010 - 1111 are used to denote the sign,
or a decimal point, or the symbol $.
• Fractions
For fractional values, the bits to the right of an assumed binary point are
interpreted as negative powers of 2. Hence 0.1010 = (1/2)+(1/8).
If the binary point is not at the extreme left end of the pattern, then the
pattern has both an integer and a fractional part. This is called a fixed point
number. For example, 000111.01 represents 7.25.

• 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

If the MSD is ‘1’ The


 number is negative
Complement of all the remaining (n-1) bits gives the
magnitude
Example: 1’s complement
• 1111001 (1)(111001)
• First (sign) bit is 1: The number is negative
One's Complement of 111001  000110
 (6)10
Range of n-bit numbers
1’s complement numbers:
0111111 --> + 63

0000110 --> + 6

0000000 --> + 0

1111111 --> - 0

1111001 --> - 6

1000000 --> - 63

ï '0' is represented by 000.....0 and 111.....1


• 7- bit number covers the range from +63 to -63.
• n-bit number has a range from +(2n-1 - 1) to -(2n-1 - 1)
1’s complement of a number
•Complement all the digits
• If A is an integer in 1's complement form, then 1's
complement of A = -A
• This applies to fractions as well.
A = 0.101 (+0.625)10
1's complement of A = 1.010, (-0.625)10
•Mixed number
B = 010011.0101 (+19.3125)10
1's complement of B = 101100.1010 (-
19.3125)10
2's complement of a number
Complement all the digits and add 1 to the LSB
If A is an integer in 1's complement form, then
2's complement of A = -A This
applies to fractions as well
 A = 0.101 (+0.625)10
2's complement of A = 1.011 (-0.625)10
Mixed number
 B = 010011.0101 (+19.3125)10
 2's complement of B = 101100.1011 (-
9.3125)10
Bit combinations

Bit -a binary digit 0 or 1


Nibble -a group of four bits
-a group of eight bits
Byte
-a group of sixteen bits;
Word
(Sometimes used to
designate 32 bit or 64
bit groups of bits)
Binary coding
• Assign each item of information a unique combination
of 1s and 0s
 n is the number of bits in the code word
 x be the number of unique words
If n = 1, then x = 2 (0, 1)
• n = 2, then x = 4 (00, 01, 10,
11)
• n = 3, then x = 8
(000,001,010 ...111)
• n = j, then x = 2j
Some codes for consideration
 Binary coded decimal codes
(we will consider only BCD)

• Unit distance codes


• Error detection codes
• Alphanumeric codes
Exercise 1;
Fill the table below and use [–] where is overflow.

DECIMAL BINARY 1’s Compliment 2’s Compliment Octal Hexa-decimal


(Unsigned) [n= 8bits] [n= 8bits]
[n= 8bits]

128
127
100
+0
-0
-100
-127
-128
Convert binary to decimals
• Now let's look at the number 110.112

DIGIT * BASE POSITION #

• 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

To find the decimal value of a binary number, we simply calculate the


value of each binary digit and then sum these values.
Convert Fraction to binary
• Consider the decimal number 11.37510. We already know
that the binary value of 11 is 10112. Now we need to find the
binary number for the fractional part 0.37510. The steps
below show how to convert this number to binary using
repeated multiplication.
1.First, we multiply 0.375 by 2 to find the most significant digit
(the rightmost digit). Since our result is less than 1, the most
significant digit in our answer is 0.
0.375*2 = 0.75
Answer:
0.0??
2.Next, we take the fractional part of our previous result (0.75)
and multiply by 2 again. Now the result is greater than 1, so
the next digit of our answer is 1.
0.75*2 = 1.5
Answer:
0.01?
3.Again we take the fractional part of our previous result (0.5)
and multiply by 2. This time our result is exactly 1, so the least
significant digit (the leftmost digit) is 1. Since the fractional part
of our result is 0, this is the last multiplication needed to find our
answer.

0.5*2 = 1.0
Answer:
0.011
We can also organize this conversion in
table form as we did with the previous one.

0.375 * 2 = 0.75 (leftmost digit)


0.75 * 2 = 1.5
0.5 * 2 = 1.0 (rightmost digit)

This time we read our answer of 0.011 from top to bottom


2

since the first multiplication gives us the most significant


digit, and the last multiplication gives us the least significant
digit.
Convert decimal number to its
binary
• In order to convert a decimal number to its binary
equivalent, we will repeatedly divide the decimal number by
2, the base of the binary system. Division by 2 will either give
a remainder of 1 (dividing an odd number) or no remainder
(dividing an even number). Collecting the remainders from
our repeated divisions will give us the binary answer.

• In this problem, the red 6 is the divisor, the blue 33 is the


dividend, the black 5 is the quotient, and the green 3 is the
remainder. We will use these same terms to describe how
binary division is done.
1.First, we need to find the smallest part of our dividend that is greater than or equal to our
divisor. Since our divisor has two digits, we start by checking the first two digits of the 10|11
dividend.

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

1.First, we note that 1102 is our multiplicand and 102 is our


110 x 10
multiplier.
2.We begin by multiplying 1102 by the rightmost digit of our
multiplier which is 0. Any number times zero is zero, so we just 110 x 10 000
write zeros below.

3.Now we multiply the multiplicand by the next digit of our


multiplier which is 1. To perform this multiplication, we just need
to copy the multiplicand and shift it one column to the left as we 110 x 10 000 110
do in decimal multiplication.

4.Now we add our results together. The product of our


multiplication is 11002. 110 x 10 000 110 1100
One's Complement
• Representing a signed number with 1's complement is done
by changing all the bits that are 1 to 0 and all the bits that are
0 to 1. Reversing the digits in this way is also called
complementing a number. Let's look at an example in 4-bit
arithmetic. How can we represent the number -510 in 1's
complement?
1. First, we write the positive value of the number 0101
in binary. (+5)
2.Next, we reverse each bit of the number so 1's 1010
become 0's and 0's become 1's (-5)
Binary Decimal
• To the right is a table of 4-bit binary numbers
0111 +7
in 1's complement notation. Notice that all of 0110 +6
the negative values begin with a 1. Whenever 0101 +5
we use 1's complement notation, the most 0100 +4
0011 +3
significant bit always tells us the sign of the 0010 +2
number. The only exception to this rule is -0. 0001 +1
In 1's complement, we have two ways of 0000 +0
1111 -0
representing the number zero. Notice also 1110 -1
that the values +0 to +7 are the same as the 1101 -2
normal binary representation. Only the 1100 -3
negative values must be complemented. You 1011 -4
1010 -5
should verify for yourself that these negative 1001 -6
values are correct by using the steps below to 1000 -7
produce this table.
Let's consider how we would solve our problem of subtracting 110 from 710
using 1's complement.

1. First, we need to convert 0001 to its negative


2
0111 (7)
equivalent in 1's complement. - 0001 - (1)

2. To do this we change all the 1's to 0's and 0's to


1's. Notice that the most-significant digit is 0001 -> 1110
now 1 since the number is negative.

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 (?)

3. This time our results does not cause an overflow, so we do


not need to adjust the sum. Notice that our final answer is 0001 (1)
a negative number since it begins with a 1. Remember that + 1000 +(-7)
our answer is in 1's complement notation so the correct 1001 (-6)
decimal value for our answer is -6 and not 9 .
10 10
•Questions:
1. What is the first thing you must do in order to solve the subtraction problem 11 - 4
10 10

using 1's complement representation? [Answer]


2. What should you do with any overflow bits that result from the solving the subtraction
problem in question 1? [Answer]
3. What is the general technique for subtracting binary numbers using 1's
complement? [Answer]
4. Solve each of the following 5-bit subtraction problems using 1's complement
representation. [Answer]
a. 00110 - 00101
2 2

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

from 7 using 2's complement.


10

1. First, we need to convert 0001 to its negative equivalent in


2
0111 (7)
2's complement. - 0001 - (1)
2. To do this we change all the 1's to 0's and 0's to 1's and add 0001 -> 1110
one to the number. Notice that the most-significant digit is 1
now 1 since the number is negative. 1111
0111 (7)
3. Next, we add the negative value we computed to 0111 . This2
+ 1111 +(-1)
gives us a result of 10110 .
2
10110 (?)
4. Notice that our addition caused an overflow bit. Whenever 0111 (7)
we have an overflow bit in 2's complement, we discard the - 0001 - (1)
extra bit. This gives us a final answer of 0110 (or 6 ).
2 10 0110 (6)
IEEE Floating Point Standard
• In 1985 a standards committee of the Institute of Electrical and Electronics
Engineers formulated and published a standard format for binary floating
point numbers. Most newer machines have adopted this standard to some
degree. Two of the four floating-point formats specified by this standard are
shown below:

IEEE Standard single precision floating point format


EEE Standard double precision floating
point format
• These formats assume a normalized mantissa of the form 1.M
where M is the 23-bit or 52-bit mantissa. Since the leading bit
(corresponding to the value 1) is always present, it is omitted from
the representation.
• Plus and minus infinity are represented by all zeros in the
mantissa and an exponent containing all ones (i.e. 127 and 1023
decimal). All zeros in both the exponent and mantissa represent
+0 or -0 depending on the sign bit.
• The exponent is represented in "excess" or "biased" form. This biased
representation of the exponent is called the characteristic. Reasons for using
the biased form include: the desire for "clean" zeros - the smallest
representable floating point number corresponds to the most negative
exponent. In biased form this most negative exponent is represented by all
zero bits.
• with biased representation the range of exponents from most negative to
the largest positive corresponds to a monotonically increasing series of
binary numbers unlike the series obtained with twos complement numbers.
Normally with an n-bit biased system the bias is 2 raised to the n-1 power, so
that the largest exponent corresponds to a characteristic containing n 1's.
For an 8-bit characteristic the bias would be 128 decimal.
• However in the IEEE standard, 127 is chosen as the bias so that the
characteristic containing all 1's can be used as a special case to represent
infinity. That is, + or - infinity are represented by the appropriate sign bit
followed by all 1's in the characteristic and all 0's in the mantissa.
• Numbers that have all 1's in the characteristic but non-zeros in the
mantissas are called NaN, not a number. These are used to represent the
results of invalid operations such as 0/0 or subtracting infinity from infinity.
Results produced by valid operations but that have exponents greater than
127 are said to cause exponent overflow. In this case plus or minus infinity
could be returned as an indicator of overflow. If the exponent of the result
is less than -127, it is said to have caused an exponent underflow
Floating Point Numbers
representation
• Once the binary fraction is obtained, the significand is generated
by shifting the radix point the proper position. The number of
places that the radix point is shifted determines the exponent.
The excess or biased form of the exponent gives the
characteristic.

• 0.12510 = ?16
• 0.125 x 16 => 2.0 thus 0.125 10 = 0.216 => 0.00102
• Example: 0.125 => 0 for sign bit, 1.0 is the significand, -3+127=124
is the characteristic
Floating Point Number Example
• How would 763.510 be represented as a single precision IEEE floating
point number?
• 763.510 = 2FB.816 = 1011111011.12 = 1.0111110111 x 2 9
• Hence the sign bit = 0
• the characteristic = 9+127 = 13610 = 100010002
• the 23-bit mantissa is 01111101110000000000000
• The corresponding IEEE single precision representation is

This 32-bit pattern can be written in short hand form using 8 hex digits:

You might also like