You are on page 1of 31

Chapter 2: Number Systems

and Codes (Continued)

1
Number Systems Conversions
Mixed Numbers

Consider a mixed number 101.012


How to convert it into decimal?

101.012= 1 x 22 + 0 x 21 + 1 x 20 + 0 x 2-1 + 1 x 2-2


= 4 + 0 + 1 + 0 + 1/4 = 5.2510

2
Number Systems Conversions
Mixed Numbers
0.812510 = ???2

3
Number Systems Conversions
Mixed Numbers
0.361510 = ???2

4
Number Systems Conversions
Mixed Numbers
13.2510 = ???2
It is convenient to
carry out separate
conversions for the
integer and fractional
parts.

5
Number Systems Conversions
Mixed Numbers

Consider the octal number 25.328


The decimal value of this number is found by completing the
summation of

2 X 81 + 5 X 80 + 3 X 8-1 + 2 X 8-2
16 + 5 + 3 X 1/8 + 2 X 1/64 = 16+5+0.375+0.03125=21.4062510

6
Number Systems Conversions
Mixed Numbers

Suppose that it is desired to convert 1001.112 into octal form.

7
Unsigned and Signed Binary Numbers
Unsigned Binary Numbers

An unsigned binary number has no arithmetic sign. Unsigned binary


numbers are therefore always positive. Typical examples are your age
or a memory address which are always positive numbers.
An 8-bit unsigned binary integer represents all numbers from 0016
through FF16 (010 through 255l0).

8
Unsigned and Signed Binary Numbers
Signed Binary Numbers

The techniques used to represent the signed integers are:


1. Sign-magnitude approach
2. Ones complement approach
3. Twos complement approach
Because the sign of a number can be either positive or negative, only
one bit, referred to as the sign bit, is needed to represent the sign. The
widely used sign convention is that if the sign bit is zero, the number is
positive; otherwise it is negative.
Also, in all three approaches, the most significant bit of the number is
considered to be the sign bit.

9
Signed Binary Numbers
Sign-magnitude approach
In sign-magnitude
representation, the most
significant bit of the given n-bit
binary number holds the sign,
and the remaining n - 1 bits
directly give the magnitude of
the negative number.
For example, the sign-magnitude
representation of +7 is 01 11 and
that of -4 is 1100.
Table 2.2 represents all possible
4-bit patterns and their meanings
in sign-magnitude form.
10
Signed Binary Numbers
Ones complement approach
In the complement approach, positive numbers have the same
representation as they do in the sign-magnitude representation. However,
in this technique negative numbers are represented in a different manner.
Before we proceed, let us define the term complement of a number. The
complement of a number A , written as Ā (or A’) is obtained by taking
bit-by-bit complement of A . In other words, each 0 in A is replaced with
1 and vice versa.
For example, the complement of the number 0100, is 1011 and that of 11
11 is 0000.

11
Signed Binary Numbers
Ones complement approach
In the ones complement approach,
a negative number, -x, is the
complement of its positive
representation.
For example let us find the ones
complement representation of
01002 (+410). The complement of
0100 is 1011, and this denotes the
negative number -410. Table 2.3
summarizes all possible 4-bit
binary patterns and their
interpretations as ones
complement numbers.
12
Signed Binary Numbers
Twos complement approach
Now, let us discuss the two’s complement approach. In this method,
positive integers are represented in the same manner as they are in the
sign-magnitude method. In other words, if the sign bit is zero, the number
is positive and its magnitude can be directly obtained by looking at the
remaining n - 1 bits.
However, a negative number -x can be represented in twos complement
form as follows:
1. Represent +x in sign magnitude form and call this result y
2. Take the ones complement of y to get y’
3. y’ + 1 is the twos complement representation of -x.

13
Binary Addition Rules

14
Signed Binary Numbers
Twos complement approach - EXAMPLES

15
Signed Binary Numbers
Twos complement approach – More
EXAMPLES

16
Signed Binary
Numbers

Twos
complement
approach

17
Comparison of Number Systems

18
Addition and Subtraction in Binary Numbers
Unsigned

19
Addition and Subtraction in Binary Numbers
Unsigned - Overflow
Digital systems usually operate on a fixed number of digits. Addition is
said to overflow if the result is too big to fit in the available digits.
A 4-bit number, for example, has the range [0, 15]. 4-bit binary addition
overflows if the result exceeds 15. The fifth bit is discarded, producing
an incorrect result in the remaining four bits. Overflow can be detected
by checking for a carry out of the most significant column.

20
Overflow!!!

21
Addition and Subtraction in Binary Numbers
2’s Complement
The addition and subtraction are carried as with unsigned numbers except
for the handling of the carry.
The computer automatically sets an overflow bit to 1 if the result of an
arithmetic operation is too big for the computer's maximum word size;
otherwise it is reset to 0.

22
Addition and Subtraction in Binary Numbers
2’s Complement

23
Addition and Subtraction in Binary Numbers
2’s Complement - Overflow
Adding two N-bit positive numbers or negative numbers may cause
overflow if the result is greater than 2N−1 −1 or less than −2N−1.
Adding a positive number to a negative number never causes overflow.

Unlike unsigned numbers, a carry out of the most significant column


does not indicate overflow. Instead, overflow occurs if the two numbers
being added have the same sign bit and the result has the opposite sign
bit.

24
Addition and Subtraction in Binary Numbers
2’s Complement - Overflow

25
Addition and Subtraction in Binary Numbers
2’s Complement - Overflow
Consider the examples for 8-bit numbers:
Let C7 be the carry out of the most significant bit (sign bit) and C6 be
the carry out of the previous (bit 6) data bit (seventh bit).
When C7 and C6 are the same, the result is always correct, and the
carry is ignored.
If C7 and C6 are different, the result is incorrect and sets the overflow
bit to 1

26
Addition and Subtraction in Binary Numbers
2’s Complement - Overflow
Case 1: C7 and C6 are the same.

27
Addition and Subtraction in Binary Numbers
2’s Complement - Overflow
Case 2: C7 and C6 are different.

28
Example (1/3)
Perform the following signed operations and comment on the
results. Assume twos complement numbers.
(a) A = 10102, B = 01002. Find A - B.
(b) Perform ( -310) - (-210) using twos complement and 4 bits.

(a) The most significant bit of A is 1, so A is a negative number whereas B


is a positive number.

Because C7 and C6 are


different, there is an overflow
and the result is incorrect.
Four bits are too small to hold
the correct answer.

29
Example (2/3)
(a) If we increase the number of bits for A and B to 5, the correct
result can be obtained as follows:

The result is correct


because C6 and C7 are
the same. The most
significant bit of the result
is 1. This means that the
result is negative.

30
Example (3/3)

(b) C3 and C4 are the same, so the result is correct.


The most significant bit of the result is 1. This
means that the result is negative.

31

You might also like