Professional Documents
Culture Documents
44 - Number Representation Number Representation 44 Number Representation Number Representation
44 - Number Representation Number Representation 44 Number Representation Number Representation
Number Representation
Numbers are key to computer operation
Instructions can be viewed as just numbers
interpreted in a particular way
D
Data
t consists
i t off numbers
b
...or other entities that can be encoded as
numbers (e
(e.g.,
g characters)
A, B, ... encoded as numbers (65, 66, etc. in ASCII)
Representing Integers
We want to store number 3465 at
memory address 2
Problem: how big can this number
be?
0
1
2
3465
Jan 2016
254
255
D i l Representation
Decimal
R
t ti
Number
N b 3465 is
i a DECIMAL number
b
base is 10
each digit of number {0,1,2,3,4,5,6,7,8,9}
Interpretation:
3465 = 3 103 + 4 102 + 6 101 + 5 100
...or base 5
in this base, each digit of number {0,1,2,3,4}
346510 = 1023305 = 1 55 + 0 54 + 2 53 + 3 52 + 3 51 + 0 50
Jan 2016
Jan 2016
Binary Numbers
Binary number: Base 2
n-digit number
Digits an-1,...,a2,a1,a0 {0,1}
Interpretation of number in base 2:
an-1 2n-1 + an-2 2n-2 + ... + a2 22 + a1 21 + a0 20
11012 = 1 23 + 1 22 + 0 21 + 1 20
= 1 8 + 1 4 + 0 2 + 1 1
= 8 + 4 + 1 = 1310
0
1
2
254
255
13
0
1
2
1101
254
255
Decimal
p
Computer
Binary
Computer
p
7
Why
h Binary Representation?
G
Greatt for
f computers!
t !
Think of each digit as a
charge stored on a
capacitor
0
1
2
if capacitor is charged, a 1 is
stored
t d
if capacitor is discharged, a
0 is stored
1101
254
255
8
Base 16 (Hexadecimal)
digits are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
10=A, 11=B, 12=C, 13=D, 14=E, 15=F
Jan 2016
10
11
Jan 2016
12
Jan 2016
13
Ones complement
representation
invert representation of
positive
iti number
b
Twos complement
representation
1 + ones complement
Jan 2016
5:
-5:
5:
-5:
5:
5:
-5:
14
Representing Integers in 2s
Complement
p
Range of integers for nbit binary number: -2
2nn-11
to +2n-1-1
With 3 bits we can
represent: -4 to +3
Leftmost bit represents
sign
0: positive
1: negative
Jan 2016
-4
-3
-2
-1
15
Binary Arithmetic
Exactly the same rules as decimal
Multiplication
Addition
+
=
11
11
17
+
=
Jan 2016
66
16
11
Jan 2016
1 complement
1s
l
t
=
0
+1
2s complement
-5
17
Exponent e
Mantissa m
((-1))s
Jan 2016
23 22
m 2e
P. R. Panda, I.I.T Delhi
18
Bits and
d Bytes
Bit - a single binary digit (0 or 1)
Byte - 8 bits
1 integer usually 32 bits (4 bytes)
or 64 (8 bytes)
Jan 2016
19