What is a Number? Types of Numbers

advertisement
Types of Numbers
Contents
Complex
Russian Dolls
Model
What is a Number?
Contents
Contents
Rational
Seminar 2
Types of Numbers
Number Systems
Representation in Computers
Contents
Real
N
Integer
Contents
Natural
N
N
Z
Z
Q
N
Z
Q
R
N Z
Q
R
C
Nine
Zulu R
QueensCRuled China
Z Q
Q R
Contents
Natural Numbers
1. seminar 2
C
R C
C
Integers
N
Z
- Closed
• Addition
• Multiplication - Closed
Q
- Not Closed
• Subtraction
- Not Closed
• Division
R
C
CE - Common era
Counting Numbers
Solving the Subtraction Problem:
• Discovery of zero (600 CE)
• Discovery of negative numbers
• Han Dynasty 220 BCE - 202 CE
• Europe: 17th century
• Addition - Closed
• Multiplication - Closed
• Subtraction - Closed
• Division - Not Closed
Solving the Division Problem:
• Discovery of rational numbers
• Ratios between two integers
1.
1. sem
Contents
Q
N
N
Q
R
Addition - Closed
1. seminar 2
Rational numbers are simple quantities:
•
•CMultiplication - Closed
• Subtraction - Closed 1.
• Division - Closed
= 0.333333333 . . . ,
Numerator
Denominator
Numerator, Denominator are integers
seminar 2
The denominator can not be 0
• Between 0 and 1 there an infinite number of rationals!
R
= 0.333333333 . . . ,
3 they can be used to represent distances as small or as
• Yet
Qlarge as we please
29
= 2.416666666 . . . ,
R 12
C 9
7
= 1.28571428571485 . . . ,
1
3
= 237
0.333333333 . . . ,
29
12
= 2.416666666 . . . ,
Contents
9
7
148
= 1.60135135135 . . .
2
2
2
=a +b
=c1.285714285714285
...,
237
148
Decimal Representation
= 1.60135135135 . . .
Fractions are ultimately periodic:
after a certain point the infinite
sequence of digits consists of some
finite sequence of digits repeated
1. seminar
indefinitely!
c 2 = a2 + b 2
C
= 2.416666666 . . . ,
= 0.333333333 . . . ,
=9 1.28571428571485 . . . ,
= 2.416666666 . . . ,
2
=
1.60135135135 . .Are
.. . . ,
= 1.28571428571485
N
Z
the rationals adequate?
Q
48
c2 = a2 + b2
= 12 + 12
= 1+1=2
Real Numbers
c2 = 2
p
= 2
p Numbers
C Numbers = Rational Numbersc+ Irrational
Real
c
=
2
c =
2
An irrational number is any number that can not be
= 1+1=2
= 1+1=2
expressed as a ratio a/b where a and b are integers and b is not equal to 0
p p
2 = 1.4142135623730950488016887 . . .
2 = 1.4142135623730950488016887 . . .
2
Since the rationals are dense, do we need any other quantity or can we
2
even fit anything
c2more
= onathe
+number
b2 line?
What is the length of the
diagonal of the unit square?
?
=
c2 =
=
=
=
2
2
a12 ++b12
112 +
+ 112= 2
1+1=2
c2 = 2
Can not be expressed as
p
the ratio of two integers!
c =
2
= 1 + 1 = It2is an irrational number!
2
c2 = a2 + b2
= 12 + 12
= 1+1=2
R
2
2
37 a + b
=
= 1.60135135135 . . .
= a2 + b 2
C
1
Z •1They
can be understood in finite terms;
Rational numbers are dense. Between any two of
them, you can always find another!
Z
2
Decimal
Representation1.ofseminar
Fractions
1
N
ntents
Q
1. seminar 2
Contents
R
Rational Numbers
1. seminar 2 Z
2
1.Z seminar 2
1. seminar 2
⇡=
⇡
C
Ind decimal notation an irrational number is any number that can not be
represented as terminating or repeating. decimals.
= 3.141592653589793238462643383279
..
e = In
2.7182818284590452353602874713526
. . can be
decimal notation a rational number is any number. that
1
represented as terminating or repeating decimals.
1
cc22
ccc2
c
=
= 2p
2
p
=
=
= 2p22
= 11 +
2 11 =
=
=
+
= 22
Real Numbers
p
p
2Some important irrational numbers in engineering!= 1 + 1 = 2
2 = 1.4142135623730950488016887 . . .
p2 = 1.4142135623730950488016887 . . .
1
1
1
1
2=
1.4142135623730950488016887
=
1C +
+ 1⇥2
+ 1⇥2⇥3
+ 1⇥2⇥3⇥4
+ .· .· .·
⇡⇡e =
1
=C
d
d
C
1 n
⇡
=
lim
1
+
⇡⇡e =
3.141592653589793238462643383279
.. .. ..
d
n!1
n
= 3.141592653589793238462643383279
= 3.141592653589793238462643383279
...
e⇡ln(x)
=x
ln(ex ) = x Euler’s number
2
e2 = 2.7182818284590452353602874713526 . . .11
1
1
1
1
ee =
= 11++1 11++ 11⇥2
+ + 11⇥2⇥3
+ + 11⇥2⇥3⇥4
+ · · ·+ · · ·
1
1⇥2
1⇥2⇥3
e = limn!1 1 +
1 n
n
1⇥2⇥3⇥4
Infinite Processes!
Since they are important numbers, we will want to represent them in a computer!
1.
1. seminar
seminar 2
2
e = limn!1 1 +
2
N
N
Contents
e = 1 + 11 +
Countability
Z
Z
ln(x)
Contents
e
Q
Q
R
R
C
C
N
1
Z
2
1
1
e=1+ +
Countable
1
1⇥2
Q
1
+ 1⇥2⇥3
R
+
n
1
e = limn!1 1 +
The base of a system specifies the number of digits used
Base-10: Decimal number system: Digits 0-9
Numbers are written and manipulated using positional notation.
N
1
Z
Q
R
1
1⇥2⇥3⇥4
C
+ ···
Uncountable
that of the integers and that of the real numbers.
1
1
1 n
n
1
eeln(x)
= =lim
x n!1
ln(ex ) =1x+
1
1⇥2⇥3⇥4
1 n
n
+ ···
1 ⇢ Q ⇢ R Number
Systems
x
N
eNln(x)
=
x
ln(e
)
=
x
⇢Q⇢R
3
2
1
0
2
1
7365
⇥1010
7365 = 7=
⇥7
103⇥
+ 310
⇥ 10+
+3
6⇥
+5+
⇥ 1060 ⇥ 10 + 5 ⇥ 10
1
n 1
1
dn ⇥ B
+ d1
Bn 2 +
· · · +10
dn2 to
⇥2Bany
+ dbase:
n
n 1 ⇥from
Lets
base
dN
⇥generalize
B
+
d
⇥
B
+
· ·1 · + d2 ⇥ B 1 + d1
n⇢
n
1
Q⇢R
If a number in the base-B number system has n digits, it is represented
as the following polynomial,
where di represents the digit in
7365
7 ⇥ 103 + 3 ⇥ 102 + 6 ⇥ 101 + 5 ⇥ 100
the i-th =
position
2
1
1101 = 1 ⇥ 23 +
1 1 ⇥ 2 + 0 ⇥ 2 + 1n 2
+ dn n2 1 ⇥ B 1 + · · ·
dn ⇥ 2
+ dn 1 ⇥ 2
+ · · · + d2 ⇥ 2 + d1
n
dn ⇥n B
1
dn ⇥ 10n
Base-2: Binary number system:
Digits 0-1
Base-8: Octal number system:
Digits 0-7
Base-16: Hexadecimal number system: Digits 0-9, Letters A-F
dn ⇥ 16n
1
+ dn
1
1
+ dn
1
⇥ 10n
⇥ 16n
2
2
+ d2 ⇥ B 1 + d1
+ · · · + d2 ⇥ 101 + d1
+ · · · + d2 ⇥ 161 + d1
B2U(0001) = 0 ⇥ 23 + 0 ⇥ 22 + +0 ⇥ 21 + 1 = 0 + 0 + 0 + 1 = 1
B2U(0101) = 0 ⇥ 23 + 1 ⇥ 22 + +0 ⇥ 21 + 1 = 0 + 4 + 0 + 1 = 5
B2U(1011) = 1 ⇥ 23 + 0 ⇥ 22 + +1 ⇥ 21 + 1 = 8 + 0 + 2 + 1 = 11
B2U(1111) = 1 ⇥ 23 + 1 ⇥ 22 + +1 ⇥ 21 + 1 = 8 + 4 + 2 + 1 = 15
B2T(0001) =
1
1⇥2⇥3
+
ln(e
1 n
n
x
eln(x) Continuous
=x
ln(ex ) = x
1. s
e22Continuum
= limHypothesis
1 + -n1There
n!1 (Cantor)
C is no set whose cardinality is strictly between
1
+
e = limDense
n!1 1 +
Are some infinite sets bigger than others? N ⇢ Q ⇢ R
1 +x1⇥2⇥3⇥4
= 1 + 1 + 1⇥2
+ 1⇥2⇥3
··
ee ln(x)
ln(e
=1x+ ·+
= 1=
+ x11 +
+) 1⇥2⇥3
1⇥2
Number Systems
=x
1
1⇥2
0 ⇥ 23 + 0 ⇥ 22 + +0 ⇥ 21 + 1 = 0 + 0 + 0 + 1 = 1
e
=x
ln(e ) =
n x
e = limn!1 31 + n1
2
1
0
If the base-B number system has n digits, it is represented
1 + 3 ⇥ 110 + 6 ⇥110 + 5 ⇥ 10
7365
e1ln(x)
= 1=+711⇥+101⇥2
+x 1⇥2⇥3 + 1⇥2⇥3⇥4 + · · ·
as the following polynomial, where di represents the digit
)=
den ⇥ B=n x1 + dln(e
⇥
B nx 2 + · · · + d2 ⇥ B 1 + d1
n
n 11
the i-th position
Q n!1
⇢R 1+ n
eN=⇢lim
If1
the base-B
number
system has n1digits, it is
represented 1101 = From
Binary
to0 Decimal
3 x Number
1 ⇥ 23 +
1 ⇥ 22 +
⇥ 21 + 1
ln(x)
7365
7 Binary
⇥ 10
+ )3=
⇥ x102 + 6System
⇥ 10 + 5 ⇥ 100
eas
=
x
ln(e
polynomial, where di represents the digit in
N the
⇢ Qfollowing
⇢R
n
1
d n ⇥ 2n 1 + d n 1 ⇥ 2n 2 + · · · + d 2 ⇥ 21 + d 1
the
dn ⇥i-th
B position
+ d3n 1 ⇥ B n 22 + · · · + d12 ⇥ B 1 + 0d1
1
7365 = 7 ⇥ 10 + 3 ⇥ 10 + 6 ⇥ 10 + 5 ⇥ 10
1101
=⇢
1n ⇥R
23 + 1 ⇥ 22 +
02 ⇥ 21 + 1
N
⇢
Q
1
n
1
Decimal:
B=10:
dn ⇥ B
+
d
+
·
·
·
+
d
n 1⇥B
2 ⇥ B + d1
n 1
n 2 2
d7365
+ 10
dn3 +
215+
n⇥2
1⇥
2 1⇥+
1 0
=7⇥
3 2⇥ 10+
+· ·6· +
⇥ d10
⇥d10
If the base-B
number nsystem
has n digits,
it is represented
n 1
2
1
ddas
⇥
10
+
d
⇥
10
+
·
·
·
+
d
⇥
10
+
n
1
n
2
1
n ⇥
B following
+ dnn 11polynomial,
⇥B
+ · ·where
· + d22 d⇥i represents
B + dd11 the digit in
n the
the i-th
Binary:
B=2:position
1101 = 1 ⇥ 23 + 1 ⇥ 22 + 0 ⇥ 21 + 1
d n ⇥ 2n
1
+ dn
1
⇥ 2n
2
+ · · · + d 2 ⇥ 21 + d 1
Binary Representation of a Positive Integer
1. Divide the value by 2 and record the remainder.
2. As long as the quotient obtained is not 0, continue
to divide the newest quotient by two and record
the remainder
3. Now that the quotient of 0 has been obtained, the
binary representation of the original value consists
of the remainders listed from right to left in the order
they were recorded.
How about from Decimal to Binary?
Examples
What is the binary representation of 8?
What is the binary representation of 5?
If the base-B number system has n digits, it is represented
as
1 the following polynomial, where di represents the digit in
the i-th position
N⇢Q⇢R
2
1101 = 1 ⇥ 23 +
21 + 11
3 1 ⇥ 2 +20 ⇥
Hexadecimal
system
7365 = 7 ⇥ 10 + 3 ⇥ 10 + 6 ⇥ 10 + 5 ⇥ 100
dn ⇥ 2nn 1 1+ dn 1 ⇥ 2n n2 +2 · · · + d2 ⇥ 21 +1d1
dn ⇥ B
+ dn 1 ⇥ B
+ · · · + d2 ⇥ B + d1
dn ⇥ 10n 1 + dn 1 ⇥ 10n 2 + · · · + d2 ⇥ 101 + d1
B=16:
dn ⇥ 16n
1
+ dn
1
⇥ 16n
2
• Since there are only 10 decimal digits but the
+ · · · + d2 ⇥ 161 + d1
base is 16, we need additional digits: A,B,C,D,E,F
• Hexadecimal is shorthand notation for long
patterns of bits.
• Each group of 4 bits can be represented by a single symbol.
• 8 bits: 2 digits, 16 bits: 4 digits, 32 bits, 8 digits
10100011 becomes A3
A 3
!
al !
m ry
x! eci ina
e
H D B
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
Some Examples
What is 11000011 in hexadecimal notation?
C 3
What is 11111101 in hexadecimal notation?
F D
What is E6 in decimal notation?
1110 0110
1
E*16 + 6*160 = 230
14*161 + 6*160 = 230
BITS - Binary Digits
Information Storage & Processing
Goal: To understand how all modern computing systems
and computation using such systems are based on binary numbers and
operations on them!
Video
Text
Symbols
Information = Bits + Context
The context provides an interpretation of the bit patterns!
The same bit pattern can mean different things.
Computers execute binary computations. Any information we
process is ultimately encoded and stored as binary numbers!
Images
Information in a computer is encoded as patterns of 1’s and 0’s.
Sound
For instance, a numerical value, character or a program instruction!
Logical Computations
1= true
0= false
And, Or
Not
Context: logic
Any process on data is ultimately encoded and stored as binary numbers!
Numerical Computations
1
0
Addition, Subtraction
Multiplication, Division
Context: Numbers
the i-th position
1101 = 1 ⇥ 23 + 1 ⇥ 22 + 0 ⇥ 21 + 1
Bits and Bytes
d n ⇥ 2n
dn ⇥ 10n
Most computers use blocks of 8 bits, or bytes,
as the smallest addressable unit of memory
!
al !
m ry
x! ci na
He De Bi
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
dn ⇥ 16n
Byte = 8 bits Binary 000000002 to 111111112 Decimal: 010 to 25510 Hexadecimal 0016 to FF16
1
+ dn
1
1
1
⇥ 2n
2
+ ··· +
d2 ⇥ and
21 +Words
d1
Bytes
n 2
⇥ 10Machine(Has(“Word(Size”(
+ · · · + d2 ⇥ 101 + d1
+ dn
1
+ dn
n 2
+ · · · + d2 ⇥ 161 + d1
1 ⇥ 16 !  Including(addresses(
! 
!  Nominal(size(of(integer0valued(data(
3
!  Most(current(machines(use(32(bits((4(bytes)(words(
Limits(addresses(to(4GB(
B2U(0001) = 0 ⇥ 2 + 0!  ⇥
22 + +0 ⇥ 21 + 1 = 0 + 0 + 0 + 1 = 1
Becoming(too(small(for(memory0intensive(applicaDons(
2
1
!  High0end(systems(use(64(bits((8(bytes)(words(
!  PotenDal(address(space(≈(1.8(X(1019(bytes(
(10004)
!  x86064(machines(support(480bit(addresses:(256(Terabytes(
2
1
!  Machines(support(mulDple(data(formats(
!  FracDons(or(mulDples(of(word(size(
2
1
!  Always(integral(number(of(bytes(
! 
B2U(0101) = 0 ⇥ 23 + 1 ⇥ 2 + +0 ⇥ 2 + 1 = 0 + 4 + 0 + 1 = 5
B2U(1011) = 1 ⇥ 23 + 0 ⇥ 2 + +1 ⇥ 2 + 1 = 8 + 0 + 2 + 1 = 11
B2U(1111) = 1 ⇥ 23 + 1 ⇥ 2 + +1 ⇥ 2 + 1 = 8 + 4 + 2 + 1 = 15
B2T(0001) =
0 ⇥ 23 + 0 ⇥ 22 + +0 ⇥ 21 + 1 = 0 + 0 + 0 + 1 = 1
B2T(0101) = 0 ⇥ 23 + 1 ⇥ 22 + +0 ⇥ 21 + 1 = 0 + 4 + 0 + 1 = 5
Metric Prefixes B2T(1011) =
WhatB2T(1111)
is a Googol?
10100
What is a current estimate
of atoms in the
“observable” universe?
1080
=
Memory
1 ⇥ 23 + 0 ⇥Storage:
22 + +1Main
⇥ 21 +
1= 8+0+2+1=
5
8+4+2+1=
1
Memory Cell: is a unit of memory (usually a byte), organized in a bit order:
1 ⇥ 23 + 1 ⇥ 22 + +1 ⇥ 21 + 1 =
Address: A “name” that uniquely identifies one cell in the computer’s main memory
• The names are actually numbers.
• These numbers are assigned consecutively starting at zero.
• Numbering the cells in this manner associates an order with the memory cells
Byte Oriented
Memory Organization
00
••
•0
• • •!
FF
••
•F
Virtual Memory: Programs refer to virtual addresses
• Conceptually, it is a very large array of bytes.
• System is actually implemented with a hierarchy of different memory types.
Measuring Memory Capacity
Word Oriented Memory Organization
! 
32-bit! 64-bit!
Bytes! Addr.!
Words! Words!
Addresses&Specify&Byte&
Loca2ons&
!  Address&of&first&byte&in&word&
!  Addresses&of&successive&words&differ&
Addr !
=!
0000
??
by&4&(328bit)&or&8&(648bit)&
Addr !
=!
0000
??
Addr !
=!
0004
??
Addr !
=!
0008
??
Addr !
=!
0008
??
Addr !
=!
0012
??
2
Number
of Bytes
e = 1 + 11 +
1
1⇥2
+
+
1
1⇥2⇥3⇥4
1 n
n
e = limn!1 1 +
eln(x) = x
1
1⇥2⇥3
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
•  Kilobyte: 210 bytes = 1024 bytes
–  Example: 3 KB = 3 times1024 bytes
•  Megabyte: 220 bytes = 1,048,576 bytes
–  Example: 3 MB = 3 times 1,048,576 bytes
•  Gigabyte: 230 bytes = 1,073,741,824 bytes
–  Example: 3 GB = 3 times 1,073,741,824 bytes
My MacBook Pro:
16GB of main memory
750GB of secondary memory (flash disk)
+ ···
ln(ex ) = x
Representing Integers
1
Representing
Integers in Computers
N⇢Q⇢R
7365 = 7 ⇥ 10
Unsigned Integers
n 1
n⇥
w=d#
of B
bits
B2U(X ) =
BinaryToUnsigned
Numeric Range
UMin = 0 000…0 UMax = 111…1
2w – 1 3
2
1
0
+ 3 ⇥ 10
23 = +
8! 6 ⇥ 10 + 5 ⇥ 10
+ dn
1
⇥ B2n2 =2 4!
+ · · · + d2 ⇥ B 1 + d1
21 = 2!
w−1
If the
base-B
number system has n digits, it is represented
i
20 = 1!
as xthe
i ⋅2following polynomial, where di represents the digit in
0! 1! 2! 3! 4! 5! 6! 7! 8! 9! 10! 11!12!13!14!15!16!
i=0
the i-th position
∑
2
1101 = 1 ⇥ 23 + 1 ⇥ 2[0001]!
+ 0 ⇥ 21 + 1
d n ⇥ 2n
dn ⇥ 10n
dn ⇥ 16n
1
long int C = 15213;
IA32!
Byte
Byte
Byte
Byte
6D
3B
00
00
+ dn
1
1
+ dn
1
[1011]!
2
+ · · · + d2 ⇥ 101 + d1
[1111]!
⇥ 10n
⇥ 16n
2
3
2
1
B2U(0101) = 0 ⇥ 2 + 1 ⇥ 2 + +0 ⇥ 2 + 1 = 0 + 4 + 0 + 1 = 5
B2U(1011) = 1 ⇥ 23 + 0 ⇥ 22 + +1 ⇥ 21 + 1 = 8 + 0 + 2 + 1 = 11
B2U(1111) = 1 ⇥ 23 + 1 ⇥ 22 + +1 ⇥ 21 + 1 = 8 + 4 + 2 + 1 = 15
Binary:
00
00
3B
6D
0011 1011 0110 1101
Hex:
3
B
6
D
Big
Endian
! 
+ · · · + d2 ⇥ 161 + d1
B2U(0001) = 0 ⇥ 23 + 0 ⇥ 22 + +0 ⇥ 21 + 1 = 0 + 0 + 0 + 1 = 1
Decimal: !15213
Sun!
6D
3B
00
00
00
00
00
00
Little
Endian
n[0101]!
2
+ dn w=4
+ · · · + d 2 ⇥ 21 + d 1
1⇥2
1
x86-64!
Big$Endian$
!  Least&significant&byte&has&highest&address&
! 
Big Endian!
0x100 0x101 0x102 0x103
Little Endian!
0x100 0x101 0x102 0x103
01
67
23
45
45
23
67
01
Li*le$Endian$
!  Least&significant&byte&has&lowest&address&
! 
Example$
!  Variable&x&has&47byte&representa9on&0x01234567&
!  Address&given&by&&x&is&0x100&
Representing Signed Integers in Computers
X"
0000"
0001"
0010"
0011"
0100"
0101"
0110"
0111"
1000"
1001"
1010"
1011"
1100"
1101"
1110"
1111"
B2U(X)&
0"
1"
2"
3"
4"
5"
6"
7"
8"
9"
10"
11"
12"
13"
14"
15"
Coding -6 in Two’s Complement Notation using 4 bits
Start with the binary
representation of 6
Given 4 bits of memory, we can represent 24 unsigned numbers
B2T(X)&
(24 - 1 if 0 is not included)
0"
1"
2"
3"
Suppose
we wanted to represent both positive and negative
4"
numbers in memory.......
5"
6"
7"
We would need to find an efficient mapping between
–8"
4
–7" our binary numbers and roughly 2 /2 positive numbers
4
and 2 /2 negative numbers
–6"
–5"
–4"
–3"
–2"
–1"
2
e = 1 + 11 +
1
1⇥2
e = limn!1 1 +
eln(x) = x
Let’s do that!
1
1⇥2⇥3
+
+
1
1⇥2⇥3⇥4
1 n
n
+ ···
ln(ex ) = x
1
N⇢Q⇢R
7365 = 7 ⇥ 103 + 3 ⇥ 102 + 6 ⇥ 101 + 5 ⇥ 100
dn ⇥ B n
Two’s Complement Examples
1
+ dn
1
⇥ Bn
2
+ · · · + d2 ⇥ B 1 + d1
If the base-B number system has n digits, it is represented
Representing
Signed Integers in Computers
as the following polynomial, where di represents the digit in
the i-th position
Comparison
with Unsigned
X"
0000"
0001"
0010"
0011"
0100"
0101"
0110"
0111"
1000"
1001"
1010"
1011"
1100"
1101"
1110"
1111"
B2U(X)&
0"
1"
2"
3"
4"
5"
6"
7"
8"
9"
10"
11"
12"
13"
14"
15"
B2T(X)&
0"
1"
2"
3"
4"
5"
6"
7"
–8"
–7"
–6"
–5"
–4"
–3"
–2"
–1"
Two’s Complement Encoding
3
2
1101 = 1 ⇥ 2 + 1 ⇥ 2 + 0 ⇥ 21 + 1
B2T (X ) =
– 23 = –8!
22 = 4!
dn ⇥ 2 w−1
+d
⇥ 2 i + · · · + d2 ⇥ 2 + d1 1
− xw−1 ⋅2 +n 1 xi ⋅2
2 = 2!
n 1
i=0
dn ⇥ 10
+ dn 1 ⇥ 10n 2 + · · · + d2 ⇥ 101 + d210 = 1!
–8!–7!–6!–5!–4!–3!–2!–1! 0! 1! 2! 3! 4! 5! 6! 7!
n 1 1 = negative Int n 2
dn Sign
⇥ 16Bit
+
16
+ · · · + d2 ⇥ 161 + d1
n 1 ⇥ Int
0 =dpositive
[0001]!
B2U(0001) = 0 ⇥ 23 + 0 ⇥ 22 +
+0 ⇥ 21 + 1 = 0 + 0 + 0 + 1 = 1
Numeric Range
TMin = –B2U(0101)
2w–1 100…0 w−2
n 1
∑
n 2
8!
[0101]!
= 0 ⇥ 23 +w=4
1 ⇥ 22 + +0 ⇥ 21 + 1 = 0 + 4 + 0 + 1 = 5
[1011]!
B2U(1011) = 1 ⇥ 23 + 0 ⇥ 22 + +1 ⇥ 21 + 1 = 8 + 0 + 2 + 1 = 11
TMax = 2w–1 – 1 Half of U -1
011…1
1
[1111]!
B2U(1111) = 1 ⇥ 23 + 1 ⇥ 22 + +1 ⇥ 21 + 1 = 8 + 4 + 2 + 1 = 15
B2T(0001) =
0 ⇥ 23 + 0 ⇥ 22 + +0 ⇥ 21 + 1 = 0 + 0 + 0 + 1 = 1
B2T(0101) = 0 ⇥ 23 + 1 ⇥ 22 + +0 ⇥ 21 + 1 = 0 + 4 + 0 + 1 = 5
B2T(1011) =
B2T(1111) =
1 ⇥ 23 + 0 ⇥ 22 + +1 ⇥ 21 + 1 =
8+0+2+1=
5
1 ⇥ 2 + 1 ⇥ 2 + +1 ⇥ 2 + 1 =
8+4+2+1=
1
3
2
1
Representing Signed Integers in Memory
Addition/Subtraction converted to Two’s Complement Notation
Decimal: !15213
int A = 15213;
IA32, x86-64!
Little
Endian
Sun!
6D
3B
00
00
00
00
3B
6D
3
Hex:
B
6
IA32!
Big
Endian
x86-64!
6D
3B
00
00
FF
FF
C4
93
Two’s Complement
Representation
Sun!
6D
3B
00
00
00
00
00
00
Sun!
93
C4
FF
FF
00
00
3B
6D
Decimal: !-15213
Binary:
1111 1111 1111 1111 1100 0100 1001 0011
F
Hex:
F
F
F
C
4
9
3
Example: 7 - 5
Numeric Ranges
Unsigned Values UMin = 0 000…0 • Select pattern length to be used
• Write down all different patterns
in the order they would appear if
counting from bottom up.
• Pick the 1st pattern with 1 as
most significant bit to represent 0
• Patterns preceding 0 are used for -1, -2, -3 ...
• Patterns proceeding 0 are used for 1, 2, 3, ...
100…0 TMax = 2w–1 – 1 111…1
011…1
For Different Word Sizes
!
UMax"
TMax"
TMin"
!
!
8"
255!
127!
-128!
16"
65,535!
32,767!
-32,768!
W"
32"
4,294,967,295!
2,147,483,647!
-2,147,483,648!
For subtraction:
• negate the number subtracted
and then add both together.
• subtraction of any combination
of signed integers uses the same
algorithm and circuitry for addition
plus an additional circuit for
negation of an integer!
Representing Signed Integers in Excess Notation
Two’s Complement Values TMin = –2w–1 UMax = 2w – 1 !
For addition:
•Same algorithm as for
binary addition.
• any extra carry bit
generated on the left is
truncated.
• addition of any combination
of signed integers uses the
same algorithm and circuitry!
D
long int C = 15213;
int B = -15213;
IA32, x86-64!
The Payoff!
0011 1011 0110 1101
Binary:
64"
18,446,744,073,709,551,615!
9,223,372,036,854,775,807!
-9,223,372,036,854,775,808!
If the pattern length is x, the difference between the
bit pattern value and the value represented is 2x-1
4
x=4, excess-8 notation, x= 5, excess-16 notation
Representing Fractions
Representing Fractions
Radix Point
Radix Point
2i#
2i$1#
4#
2#
1#
• • •!
bi# bi$1# •••# b2# b1# b0# b$1# b$2# b$3# •••# b$j#
! 
Representa6on#
• • •!
1/2#
1/4#
1/8#
2$j#
!  Bits#to#right#of#“binary#point”#represent#frac6onal#powers#of#2#
!  Represents#ra6onal#number:#
Representable Numbers
Assuming finite length encodings:
! 
Limita&on)
!  Can)only)exactly)represent)numbers)of)the)form)x/2k)
!  Other)ra&onal)numbers)have)repea&ng)bit)representa&ons)
! 
Value
)Representa&on)
!  1/3
!  1/5
!  1/10
)0.0101010101[01]…2
So, we must eventually truncate!
)0.001100110011[0011]…2
)0.0001100110011[0011]…2
Can approximate with increasing
accuracy by lengthening the
binary representation
Shifting the decimal point 1 position to the left
has the effect of dividing the number by 10.
Shifting the binary point 1 position to the left
has the effect of dividing the number by 2.
decimal point 1 position to the right
Shifting the binary
has the effect of multiplying the number by 10.
Shifting the binary point 1 position to the right
has the effect of multiplying the number by 2.
101.11 = 5 3/4
145.238
14.5238
1452.38
10.111 = 2 7/8
1011.1 =11 1/2
Floating Point Representation
Representing a real value in a computer:
• The sign - positive or negative
• The mantissa - consists of digits in the value with the radix
point assumed to the left
• The exponent - which determines how the radix point is
shifted relative to the mantissa (can be positive or negative)
Let’s Assume an 8-bit fixed
representation
(usually much larger 64 bits):
• sign: 1 bit,
• exponent: 11 bits,
• mantissa: 52 bits
The representation is called floating point because the
number of digits is fixed but the radix point floats.
• a positive exponent shifts the radix point to the right
• a negative exponent shifts the radix point to the left
Decoding the value 01101011
0 1 1 0 1 0 11
. 1011
2
110
10. 11
2+0+1/2+1/4 = 2 3/4
+ 2 3/4
Exponent encoded
in excess-4
Extract Mantissa
1001
-1
Translate to
decimal form
1 to the right
(+1)
Determine direction and
length to move radix
point to recover the
original binary number
Exponent encoded
in excess-4
0
Translate to
decimal form
Check sign bit
0 is positive
1 is negative
0.375
0 110 1010
10. 101
2+1/2+1/8=2 5/8
Must truncate the
rightmost 1 (1/8)
Encode in exponent
field using excess notation
Encode sign bit
0 is positive
1 is negative
Move radix point
to the left 1
Truncation Errors: Encoding the value 2 5/8 (2.625)
Copy the pattern
into the mantissa
(left to right)
. 1001
Extract Exponent
Interpret in excess-4
+ 3/8
Exponent encoded
in excess-4
Imagine the radix
point to the left of
the mantissa value
Extract Mantissa
0/2+1/4+1/8 = 3/8
Check sign bit
0 is positive
1 is negative
Encode the number
in binary notation
011
. 01100
Starting with leftmost 1
101
. 1100
Move radix point
to the right 2
2.75
1. 001
0 0 1 1 1 10 0
Extract Exponent
Interpret in excess-4
Encoding the value 1 1/8 (1.125)
0 101 1001
Decoding the value 00111100
Exponent encoded
in excess-4
Result:
01101010 = 2 1/2
Truncation or
Rounding error!
1010
Encode the number
in binary notation
Copy the pattern
into the mantissa
(left to right)
Starting with leftmost 1
. 1010
Imagine the radix
point to the left of
the mantissa value
2 to the right
(+1)
Determine direction and
length to move radix
point to recover the
original binary number
110
0
Encode in exponent
field using excess notation
Encode sign bit
0 is positive
1 is negative
Truncation Errors
Can cause significant problems in applications requiring high precision!
Worrying about Precisions
! 
sexp
There are many more repeating decimal numbers in binary than in
decimal notation. Example: 1/10
Arithmetic with accumulated rounding errors can be problematic:
8 bit representation:
2 1/2 + 1/8 + 1/8 is not the same as 1/8 + 1/8 + 2 1/2 !!
Single'precision:'32'bits'
1
! 
8-bits
23-bits
1
frac
11-bits
52-bits
Extended'precision:'80'bits'(Intel'only)'
sexp
Topic: Numerical Analysis
Precision: 7 decimal digits
Double'precision:'64'bits'
sexp
! 
10^-37 to 10^38
frac
1
15-bits
frac
63 or 64-bits
Single Precision
•Encodes very small real numbers
and very large real numbers
• very accurate precision to 7
decimals...
IEEE Floating Point Standard 754
! 
IEEE#Standard#754#
!  Established#in#1985#as#uniform#standard#for#floa;ng#point#arithme;c#
! 
Before#that,#many#idiosyncra;c#formats#
!  Supported#by#all#major#CPUs#
! 
Driven#by#numerical#concerns#
!  Nice#standards#for#rounding,#overflow,#underflow#
!  Hard#to#make#fast#in#hardware#
! 
Numerical#analysts#predominated#over#hardware#designers#in#defining#
standard#
The High Cost of Floating Point Overflow!
Ariane 5 was designed by the European Space Agency (ESA) as a
replacement for the successful Ariane 4 launcher. The intention was to
create a reliable, high capacity, launch vehicle for ESA that could be used
to support their contribution to the International Space Station as well as a
range of other commercial and scientific launches.
On June 4, 1996, the US$500 million space craft was launched for the
first time
Sadly, the primary cause was found to be a piece of software which had been retained from the
previous launcher’s systems and which was not required during the flight of Ariane 5. The
software was used in the Inertial Reference System (SRI) to calculate the attitude of the launcher.
In Ariane 4, this software was allowed to continue functioning during the first 50 seconds of flight
as it could otherwise delay launching if the countdown was halted for any other reason, this was
not necessary for Ariane 5. Additionly, the software contained implicit assumptions about the
parameters, in particular the horizontal velocity that was safe for Ariane 4, but not Ariane 5.
The failure occurred because the horizontal velocity exceeded the maximum value for a 16
bit unsigned integer when it was converted from it's signed 64 bit representation. This failure
generated an exception in the code which was not caught and thus propagated up through the
processor and ultimately caused the SRI to fail. The failure triggered the automatic fail-over to the
backup SRI which had already failed for the same reason. This combined failure was then
communicated to the main computer responsible for controlling the jets of the rocket, however,
this information was misinterpreted as valid commands. As a result of the invalid commands, the
engine nozzles were swung to an extreme position and the launcher was destroyed shortly
afterwards.
Storing Text/Symbols
ASCII
American Standard Code for
Information Interchange
Additional Slides if
extra time
Extended Ascii Character Set
ASCII
Character
Set
+
ASCII Character Set
Originally used 7 bits/character +
1 bit used as a check bit
Unicode Character Set
Extended ASCII
Character Set
Uses 8 bits/character
256 characters
Additional accented
and other
special symbols
Enough for english
but not for other
languages!
Goal: To represent every character in every language
on the planet, including ideograms, archaic languages,
all symbols, etc.
• Includes extended ASCII with same encoding
• Generally uses 16 bits per character (65536 chars)
• Used by most modern programming languages today
Representing Strings
! 
Storing Images
Strings(in(C(
!  Represented)by)array)of)characters)
!  Each)character)encoded)in)ASCII)format)
Standard)79bit)encoding)of)character)set)
Hex
!  Character)“0”)has)code)0x30)
–  Digit)i))has)code)0x30+i)
!  String)should)be)null9terminated)
!  Final)character)=)0)
char S[6] = "18243";
• A photograph is an analogue representation of an image
• it is continuous across its surface and colors blend into each other.
• Digitizing an image involves representing it as a collection of individual
dots called pixels (picture elements)
! 
! 
Compa.bility(
!  Byte)ordering)not)an)issue)
Linux/Alpha!
• each pixel is composed of a single color
• the number of pixels used in an image is called its resolution
• if the resolution is high enough the human eye is tricked into
Sun!
31
31
38
38
32
32
34
34
33
33
00
00
thinking it is viewing a continuous picture.
•
• Apple: New retina displays
Two types of formats
• Raster graphics format - pixel by pixel representation. (BMP, GIF,
JPEG, PNG)
• Vector graphics format - describe in terms of lines and geometric
shapes (FLASH, SVG)
Storing Images - Raster Graphics
Color Images- Raster Graphics Format
A Digital Image is a 2D array (matrix) of numbers
RGB Encoding
Each pixel is encoded using 3 bytes, each measuring the intensity of the three
primary colors, red, green and blue
• Intensity Images: Photographic like images encoding light intensities. Sensors: cameras, infrared
• Range Images: Shape like images encoding shape and distance. Sensors: sonar, laser
Pixel - Picture Element
Bitmap - Collection of encoded pixels
Lots of Data!!!
3x3 bitmap using
grayscale encoding
1 byte/pixel
Different resolutions
1000x1000 pixel image = 1MegaPixel Image
3x1000 x 1000 = 3 MegaByte= 24MegaBit!
Vector Graphics Format
Storing Sound
• An image is described in terms of lines and geometric shapes
• A vector graphic is a series of commands that describe a line’s
• Sound is perceived when a series of air compressions vibrate a membrane in our
• Files sizes tend to be small in this format
• Each pixel does not have to be described
• Size is dependent on the number of items in the image
• Advantages
• Raster graphic has to be encoded multiple times to account for
• Stereo system
• sends an electrical signal to a speaker to produce sound
• the signal is an analog representation of the sound wave
• the speaker receives a signal and causes the membrane to vibrate, which in
• Vector graphics can be resized mathematically with changes
• Representing audio data on a computer
• The sound wave needs to be digitized
• An analogue signal varies in voltage continuously
• To digitize it, we periodically measure the voltage and record the appropriate
direction, thickness, and color
different sizes and proportions
calculated dynamically if needed.
• Disadvantages
• Vector graphics is not good for
representing real-world images
Storing Sound
ear which then sends signals to the brain
• Sound is defined in nature as an air wave that interacts with the brain
turn vibrates the air, which in turn vibrates the airdrum
• The trick is to recreate the original signal in this manner
numerical value. (We sample the signal)
Storing Video
• A video is a sequence of images. Most often shown at 25 frames per second
• Due to the large amount of data involved, each image must be compressed in some manner
• Codec (COmpressor/DECompressor)
• A video codec refers to the methods used to shrink the size of a movie so it can be played
Telephone: 8000 samples/second
CD Quality: 44,100 samples/second
• 16 bits/sample (mono)
• 32 bits/sample (stereo)
• For stereo: each second of music
requires more than a million bits!
on a computer, streamed or transferred across the network
• Lossy/Lossless
• Lossy compression (some data can not be retrieved)
• Lossless compression (original data can be retrieved)
Signal Processing
Information
Theory
• Two types of compression
• Temporal compression
• looks for differences between two frames and saves the changes
• Spatial compression
• removes redundant information
• blue sky: store the color and area coordinates instead of all pixels.
Some
Codecs
•
• Sorenson, Cinepak, Real Video, MPEG
Data Compression Techniques
• Run-Length Encoding
• Huffman Encoding
Abstraction
Where are We?
Discrete
Mathematics
Computation
Arithmetical & Logical Computations
Information
Theory
Information
Bits, Bytes, Words, Representations
Download