The Need For Number System?
The Need For Number System?
Digital systems are built from circuits that process binary digits0s and 1s
But very few real-life problems are based on binary numbers or
any numbers at all.
Correspondence between the binary digits processed by
digital circuits and real-life numbers and conditions must be
established.
1
Preliminaries
1. A number system consists of an order set of symbols (digits) with
relations defined for +,-,*, /
2. The radix (or base) of the number system is the total number of
digits allowed in the the number system.
Binary: 0, 1
Octal: 0,1,..,7
Outline
Number Systems
Positional Notations
Number Systems & Base-R to Decimal Conversion
Conversion between bases
Binary Arithmetic Operations
How to represent Negative Numbers
Comparison of Sign-and-Magnitude and Complements
Positional Notations
Weighted-positional notation
Decimal number system, symbols = { 0, 1, 2, 3, ,
9}
Position is important
Example:(7594)10 = (7x103) + (5x102) + (9x101) +
(4x100)
The value of each symbol is dependent on its type
and its position in the number
In general, (anan-1 a0)10 = (an x 10n) + (an-1 x 10n-1)
+ + (a0 x 100)
Positional Notations
Fractions are written in decimal numbers after the
decimal point.
(2.75)10 = (2 x 100) + (7 x 10-1) + (5 x 10-2)
In general, (anan-1 a0 . f1f2 fm)10 = (an x 10n) +
(an-1x10n-1) + + (a0 x 100) + (f1 x 10-1) + (f2 x 10-2)
+ + (fm x 10-m)
Decimal-to-Base R Conversion
Algorithm 1
Step 1: Break the number in two parts: Whole number
and fraction part.
Step 2: Repeated Division-by-R Method (for whole
numbers)
Carry
0
1
0
1
MSB
LSB
11
Sum-of-Weights Method
Determine the set of binary weights whose sum is
equal to the decimal number.
(9)10 = 8 + 1 = 23 + 20 = (1001)2
(18)10 = 16 + 2 = 24 + 21 = (10010)2
(58)10 = 32 + 16 + 8 + 2 = 25 + 24 + 23 + 21 = (111010)2
(0.625)10 = 0.5 + 0.125 = 2-1 + 2-3 = (0.101)2
12
1
256 128 64 32 16 8 4 2 1
Now subtract 128 from 146 which equals to
18.Again check the nearest small number to 18
is 16.Write 1 at this place and keep other
positions in between them as 0
1 0 0 1
256 128 64 32 16 8 4 2 1
14
1 0 0 1 0 0 1 0
256 128 64 32 16 8 4 2 1
The output is
10010010
15
Summary:
Conversion between Bases
Base-R to decimal: multiply digits with their
corresponding weights
Decimal to binary (base 2)
whole numbers: repeated division-by-2
fractions: repeated multiplication-by-2
Decimal to base-R
Base-R
Decimal
Base-2
Base-3
Base-4
.
Base-R
17
Binary-Octal/Hexadecimal Conversion
Binary Octal: Partition in groups of 3
(10 111 011 001 . 101 110)2 = (2731.56)8
Octal Binary: reverse
(2731.56)8 = (10 111 011 001 . 101 110)2
Binary Hexadecimal: Partition in groups of 4
(101 1101 1001 . 1011 1000)2 = (5D9.B8)16 = 0x5D9.B8
Hexadecimal Binary: reverse
(5D9.B8)16 = (101 1101 1001 . 1011 1000)2
18
Subtraction
0+0 = 0
0-0 = 0
0+1 = 1
1+0 = 1
1-0 = 1
1+1 = 1 0 (carry)
1-1 = 0
Multiplication
0*0 = 0
0*1 = 0
1*0 = 0
1*1 = 1
19
(11011)2
+ (10011)2
(101110)2
(647)10
+ (537)10
(1184)10
20
Carries
1
0
0
1
0
0
1
1
0
1
0
1
0
1
0
1
0
0
1
0
1
1
1
1
1
0
1
1
0
1
21
(25)10
- (19)10
(06)10
22
Borrows
0
0
0
0
0
0
1
1
0
0
1
1
0
0
0
1
0
0
1
1
0
0
1
1
1
0
1
1
0
0
23
(11001)2
x (10101)2
(214)10
x (152)10
(11001)2
(11001)2
+(11001)2
(1000001101)2
(428)10
(1070)10
+(214)10
(32528)10
Multiplicand
Multiplier
Partial
products
Result
24
Multiply 12 and 9
12=1100
Q
9=1001
B
Assume A=0000 initially and form the table
A_ Q_ B
25
26
27
28
sign
magnitude
30
+(127)10
-(127)10
Zeroes:
0 0000000 +(0)10
1 0000000 -(0)10
Complement representation
In complement representation, a positive number is
represented as it is (like an unsigned positive number)
A negative number, however, is represented by taking the
complement of unsigned number.
Complement numbers can help perform subtraction. With
complements, subtraction can be performed by addition.
A single circuit can be used to perform both addition and subtraction.
32
Complements
In general, for Base-r number N having n integer and m
fractional digits, there are:
(i) Diminished Radix (or r-1s) Complement
Nr1 r n N r m
(ii) Radix (or rs) Complement
Nr r n N
For Base-2 number, we have:
(i) 1s Complement: N1= 2n - |N| 2-m
(ii) 2s Complement: N2= 2n - |N|
33
1s Complement (I)
34
1s Complement (II)
For 8-bits number system:
Largest Positive Number:
0 1111111 +(127)10
1 0000000
Zeroes:
-(127)10
0 0000000
1 1111111
35
1s Complement (III)
Given a number x which can be expressed as an nbit binary number, its negative value can be obtained
in 1s-complement representation using:
- x = 2n - x - 1
Example: With an 8-bit number 00001100, its
negative value, expressed in 1s complement, is
obtained as follows:
-(00001100)2 = - (12)10
= (28 - 12 - 1)10
= (243)10
= (11110011)1s
36
2s Complement (I)
2s complement of a negative number is
obtained by inverting all the bits and adding 1.
Examples:
1. 2s complement of (00000001)2
= (11111110)1s
(invert)
= (11111111)2s (add 1)
2. 2s complement of (01111110)2
= (10000001)1s
(invert)
= (10000010)2s (add 1)
37
2s Complement (I)
Example:
1. (+14)10 = (00001110)2 = (00001110)2s
2. (-14)10 = -(00001110)2 = (11110010)2s
3. (-80)10 = (?) 2 = (?)2s
38
2s Complement (II)
Given a number x which can be expressed as an n-bit
binary number, its negative number can be obtained in
2s-complement representation using:
- x = 2n - x
Example: With an 8-bit number 00001100, its negative
value in 2s complement is thus:
-(00001100)2 = - (12)10
= (28 - 12)10
= (244)10
= (11110100)2s
39
2s Complement (III)
Largest Positive Number:
0 1111111
+(127)10
-(128)10
0 0000000
40
Sign-andMagnitude
1s
Comp.
2s
Comp.
+7
+6
+5
+4
+3
+2
+1
+0
0111
0110
0101
0100
0011
0010
0001
0000
0111
0110
0101
0100
0011
0010
0001
0000
0111
0110
0101
0100
0011
0010
0001
0000
41
Comparisons of Sign-and-Magnitude
and Complements (II)
Example: 4-bit signed number (negative values)
Value Sign-and1s
2s
Magnitude
Comp.
Comp.
-0
-1
-2
-3
-4
-5
-6
-7
-8
1000
1001
1010
1011
1100
1101
1110
1111
-
1111
1110
1101
1100
1011
1010
1001
1000
-
1111
1110
1101
1100
1011
1010
1001
1000
43
Use of complements
Complement number system is used to minimize the
44
Overflow (I)
Signed binary numbers are of a fixed range.
If the result of addition/subtraction goes beyond this
range, overflow occurs.
Two conditions under which overflow can occur are:
(i) positive add positive gives negative
(ii) negative add negative gives positive
45
2s complement addition
Algorithm:
1. Perform binary addition on the two numbers.
2. Ignore the carry out of the MSB.
3. Check for overflow: Overflow occurs if the carrier into and
out of the MSB are different.
46
2s complement subtraction
Algorithm for performing A - B:
A-B = A + (-B)
1. Take 2s complement of B by inverting all the bits and
adding 1
2. Add the 2s complement of B to A
47
Examples: 2s addition/Subtraction
4-bits system
+3
+ +4
---+7
----
0011
+ 0100
------0111
------+6
+ -3
---+3
----
0110
+ 1101
------10011
-------
-2
1110
+ -6 + 1010
----------8
11000
-------------No Over Flow
+4
+ -7
----3
----
0100
+1 001
------1101
------48
Examples: Overflow in
2s addition/Subtraction
4-bits system
-3
+ -6
----9
----
1101
+ 1010
------10111
------+7
+5
+ +6
---+11
----
0101
+ 0110
------1011
-------5
49
1s complement
Addition/Subtraction rules
Algorithm C=A+B:
1. Perform binary addition on the two numbers
2. If there is a carry out of the MSB, add 1 to the result (to get C)
3. Check for overflow: if carried into and out of of MSB are different
and C is opposite sign of A and B
Algorithm A-B
Examples: 1s addition/subtraction
+3
+ +4
---+7
----
0011
+ 0100
------0111
-------
-2
+ -5
----7
----
1101
+ 1010
------10111
+ 1
------1000
+5
+ -5
----0
----
0101
+ 1010
------1111
-------
-3
1100
+ -7 + 1000
----------10
10100
---+ 1
------0101 ov
51
binary point
54
integer part
binary point
fraction part
56
mantissa
exponent
57
58
= (0.024)10 x 1032
(normalise)
= (0.24 x 1031)10
59
60
61
0
0000
5
0101
1
0001
6
0110
2
0010
7
0111
3
0011
8
1000
4
0100
9
1001
0
0000
5
0101
1
0001
6
0110
2
0010
7
0111
3
0011
8
1000
4
0100
9
1001
Examples:
(234)10 = (0010 0011 0100)BCD
(7093)10 = (0111 0000 1001 0011)BCD
(1000 0110)BCD = (86)10
(1001 0100 0111 0010)BCD = (9472)10
Notes: BCD is not equivalent to binary.
Example: (234)10 = (11101010)2
63
64
Character
0
1
...
9
:
A
B
...
Z
[
\
ASCII Code
0110000
0110001
...
0111001
0111010
1000001
1000010
...
1011010
1011011
1011100
65
000
NUL
SOH
STX
ETX
EOT
ENQ
ACK
BEL
BS
HT
LF
VT
FF
CR
O
SI
001
DLE
DC1
DC2
DC3
DC4
NAK
SYN
ETB
CAN
EM
SUB
ESC
FS
GS
RS
US
010
SP
!
#
$
%
&
(
)
*
+
,
.
/
MSBs
011
100
0
@
1
A
2
B
3
C
4
D
5
E
6
F
7
G
8
H
9
I
:
J
;
K
<
L
=
M
>
N
?
O
101
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_
110
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
1000001 (65
in decimal)
111
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
DEL
66
67
0111010 1
1000001 1
1000010 1
...
1011010 1
1011011 0
1011100 1
68
0110
0001
1011
1111
1001
0101
1
0
0
1
1
0
Column-wise parity
Row-wise parity
70
Complements
Diminished-Radix Complements
Radix Complements
Subtraction using 2s-complement
Subtraction using 1s-complement
Overflow
Fixed-Point Numbers
Floating-Point Numbers
Arithmetic with Floating-Point Numbers
71