Number Systems
We use numbers in daily life as a quantization
tool. A numeral is an expression (symbol) that
represents a number.
Numbers are abstractions that in turn represent
quantity: count, length, money, mass, duration
of time, etc.
Unfortunately, numbers can be represented in
many different ways. Also, a number may have
extra information associated with it, which
increases the choice of ways to represent it.
Number Systems
ELE 107
Computers and Programming I
Number Systems
Number Systems
Number Systems
In Roman number system a symbol always
represents the same weight:
I = 1 , V = 5 , X = 10 , L = 50 , C = 100
D = 500 , M = 1000.
Number Systems
Number Systems
Number Systems
Number Systems
(734)14
4196 + 314 + 71
78410 + 4210 + 710
7196 + 314 + 41
137210 + 4210 + 410
(833)10
437
734
Number Systems
10
Number Systems
General form:
Position:
n n-1 2 1 0 . -1 -2 -m
Position value: r n r n-1 r2 r1 r0 . r -1 r -2 r -m
Number:
xn xn-1 x2 x1x0 . x-1 x-2 x-m
where,
r is the base of the number N,
xn is the most significant digit (MSD),
x-m is the least significant digit (LSD).
(1418)10
734
Number Systems
437
12
Number Systems
Representation of Numbers
Each number has a
unique representation.
Counting:
When you run out of
digits, make it a zero
and increment the next
place value to the left.
99 becomes 100
13
-1 -2
10 -1 10 -2
3
5
15
0
20
1
-1 -2
2 -1 2 -2
0
1
16
Number Systems
Decimal
Decimal: Base 10
00
Binary: Base 2
01
02
Octal: Base 8
03
Hexadecimal: Base 16
04
Octal and Hex forms are 05
06
more convenient for
07
humans to use
08
Dont have to deal with
09
long and confusing strings 10
11
of 1s and 0s
12
Most computer manuals use13
either octal or hex numbers 14
Binary
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
15
1111
1
21
0
14
Binary Numbers
1
101
4
Decimal Numbers
2
102
6
Binary
Decimal
D = xk r k
k = -m
17
Octal Hexadecimal
00
0
01
1
02
2
03
3
04
4
05
5
06
6
07
7
10
8
11
9
12
A
13
B
14
C
15
D
16
E
17
F
18
Binary
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
14
1110
15
1111
Octal Numbers
Octal Hexadecimal
00
0
01
1
02
2
03
3
04
4
05
5
06
6
07
7
10
8
11
9
12
A
13
B
14
C
15
D
16
E
17
F
19
0
160
1
81
4
0
80
2
26 25 24 23 22 21 20
64+0+16+0+0+2+1 = (83)10
21
Binary-to-Decimal Conversion
20
21
22
23
24
25
26
27
28
29
210
211
212
213
214
215
216
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
1K
2K
4K
8K
16K
32K
64K
22
Decimal-to-Binary Conversion
Repeated
Subtraction
2
1
0
-1
-2
(100.101)
2 = 12 + 02 + 02 + 12 + 02 + 12
3
= 4 + 0 + 0 + + 0 + = (4.625)10
(111.10)2 = 122 + 121 + 120 + 12-1 + 02-2
= 4 + 2 + 1 + + 0 = (7.5)10
(011.001)2 = 022+121+120+02-1+02-2+12-3
= 0 +2 + 1 + 0 + 0 + = (3.125)10
ELE 107 Dr. Derya Altunay
20
-1 -2
8 -1 8 -2
3
0
1010011
-1 -2
16 -1 16 -2
3
2
82
6
Binary-to-Decimal Conversion
Hexadecimal Numbers
2
162
23
24
Decimal-to-Binary Conversion
Start with decimal integer N = (25)10
Decimal-to-Binary Conversion
Repeated
Subtraction
Repeated
Subtraction
+ 23 + + 21 + 20
1 0 1 1)2
26
Decimal-to-Binary Conversion
Let N be a decimal integer:
512 = 29
128 = 27
64 = 26
8 = 23
2 = 21
1 = 20
25
Let N = (715)10
Decimal-to-Binary Conversion
Let N= (109)10
Repeated
109/2 = 54 remainder 1 (l.s.b)
Division
54/2 = 27 remainder 0
27/2 = 13 remainder 1
13/2 = 6 remainder 1
Read
6/2 = 3 remainder 0
backwards
3/2 = 1 remainder 1
1/2 = 0 remainder 1 (m.s.b)
Repeated
Division
(109)10 = (1101101)2
27
28
Binary Octal
Binary Hexadecimal
(3
( 2
7 . 1
5 )8
(2
( 2
6 . 5
4 )8
29
C .
D )16
3.
C )16
30
Octal Hexadecimal
Go through decimal:
Hex Decimal Octal
Octal Decimal Hex
31
Decimal to Binary
(6.6875)10 = ( ? )2 = (110.1011)2
Integer part:
6/2 = 3 remainder 0 (l.s.b)
3/2 = 1 remainder 1
1/2 = 0 remainder 1 (m.s.b)
Fraction part:
0.6875 x 2 = 1.3750 (m.s.b)
0.3750 x 2 = 0.7500
0.7500 x 2 = 1.5000
0.5000 x 2 = 1.0000 (l.s.b)
Decimal to Octal
Read
up
(167.6875)10 = ( ? )8 = (247.54)8
Integer part:
167/8 = 20 remainder 7 (l.s.d)
20/8 = 2 remainder 4
2/8 = 0 remainder 2 (m.s.d)
Fraction part:
Read
down
Read
up
Read
down
Decimal to Hexadecimal
(1631.78125)10 = ( ? )H = (65F.C8)H
Integer part:
1631/16 = 101 remainder 15 = F (l.s.d)
101/16 = 6 remainder 5
6/16 = 0 remainder 6 (m.s.d)
Fraction part:
32
34
Notes on Fractions
Radix point (number point)
Read
up
Read
down
35
36
Notes on Fractions
Notes on Fractions
(4276)10
Shift the radix point one place to the left
Example: (427.6)10
37
(42.76)10
38
Notes on Fractions
Notes on Fractions
(0.10101)2 = (0.65625)10
(0.4293)10
Position
10-1
10-2
10-3
10-4
Value
1/10
1/100
1/1000
1/10000
Position
2-1
2-2
2-3
2-4
2-5
Value
1/2
1/4
1/8
1/16
1/32
Sum
Sum
.4
.02
.009
.0003
39
Notes on Fractions
0.125
0.03125
40
Notes on Fractions
(0.6875)10 = (0.1011)2
(0.9375)10 = (0.74)8
0.6875 x 2 = 1.3750
0.9375 x 8 = 7.5000
0.3750 x 2 = 0.7500
0.5000 x 8 = 4.0000
0.7500 x 2 = 1.5000
(terminates)
(0.513)10 = (?)8
0.5000 x 2 = 1.0000
(terminates)
ELE 107 Dr. Derya Altunay
.5
0 x 1/16 1 x 1/32
41
0.513 x 8 = 4.104
0.104 x 8 = 0.832
0.832 x 8 = 6.656
0.656 x 8 = 5.248
0.248 x 8 = 1.984
. . . (does not terminate!)
ELE 107 Dr. Derya Altunay
42
Notes on Fractions
Notes on Fractions
0.975 x 8 = 7.800
0.800 x 8 = 6.400
0.400 x 8 = 3.200
0.200 x 8 = 1.600
0.600 x 8 = 4.800
0.800 x 8 = 6.400
(repeates!)
43
Number Ranges
Data Representation
When we communicate with each other, the information
is represented in an understandable notation, e.g., we use
216-1
Integer range:
0 to
(0 to 65535)
16
Fraction range:
0 to (2 -1) / 216
(0 to 65535/65536 = 0.9999847412)
Data Representation
Humans:
Computers:
Text, numbers,
sounds
???
Text, numbers,
images, sounds
Text, numbers,
images, sounds
Numeric
Character
Visual
Audio
Instructional
Binary Numbers
ELE 107 Dr. Derya Altunay
46
Data Representation
Internal
Text, numbers,
images, sounds
44
47
48
Binary Systems
Binary Systems
Open circuit
Closed circuit
49
Binary Systems
Binary systems have two
values
Zero and One
Zero
0
False
Off
Low V
0V
Current
N-S polar.
Cold
50
Binary Systems
One
1
True
On
High V
5V
No current
E-W polar.
Hot
51
ON
OFF
Bits as Instructions
Off/On Switches
OFF
or
ON
53
54
Zero or One?
The Bit
or
one bit
two bits
three bits
Each 0 or 1
in the binary
system is
called a bit.
56
Representation of Numbers
The Byte
A group of 8 bits is called a byte.
= J
Storing Bytes
58
Computer Word
57
60
10
Bits as Codes
Keyboard character
61
62
Binary Codes
ELE 107
Computers and Programming I
63
Terminology
A codeword (encoding) is a symbolic
representation based on the binary
alphabet, that is a sequence of 1s and 0s.
64
65
66
11
Terminology
Terminology
An n-bit binary code is a group of n bits that
assume up to 2n distinct combinations of 1s
and 0s.
For example, a set of 4 distinct numbers can
be represented by 2-bit codes such that each
number in the set is assigned exactly one of
the combinations in {00,01,10,11}.
67
Terminology
BCD
70
BCD
BCD
Decimal Symbol
0
1
2
3
4
5
6
7
8
9
68
71
BCD Digit
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
72
12
BCD
BCD is a weighted code because each
decimal digit can be obtained by assigning a
fixed weight to each codeword bit.
The weights are 8, 4, 2, and 1 8421 code
Other binary codes besides BCD exist to
represent decimal digits:
2421 code
Excess-3 (XS-3) code
Bi-quinary code
1-out-of-10 code, etc.
ELE 107 Dr. Derya Altunay
73
74
75
76
Gray Code
77
78
13
Gray Code
Gray Code
Gray Code
Binary to Gray :
g n = bn
g i = bi bi +1 ;
0 i n 1
(1 0 0 1 1 0)2 = (1 1 0 1 0 1)GRAY
Gray to Binary :
80
Characters: a b X Y
Number digits: 0 1 8 9
Punctuation marks: : ; ? !
Special-purpose characters: # & $ %
bn = g n
bi = g n g n 1 L g i
( 0 i n 1)
(1 0 1 1 0 1)GRAY = (1 1 0 1 1 0)2
ELE 107 Dr. Derya Altunay
81
Alphanumeric Codes
82
Representing Characters
ASCII : most widely used coding scheme
Unicode : developed for worldwide use
83
84
14
ASCII
ASCII
ASCII
ASCII
87
88
86
89
Decimal
0 31
ASCII
Invisible (control characters)
32 47
48 - 57
58 64
65 - 90
91 96
97 122
123 127
90
15
Decoding
Unicode
91
92
93
94
95
96
16
Character Encodings
Error Detection/Correction
Bit Flip
Example
Suppose that you
Bit
send the ASCII
flipped
encoding for the
none
character S
0
(101 0011).
1
Show the
2
different values
3
that a receiver
4
will receive if a
5
single bit is
flipped during
6
transmission.
99
Hamming Distance
Received
pattern
101 0011
101 0010
101 0001
101 0111
101 1011
100 0011
110 0011
001 0011
Received
symbol
S
R
Q
W
[
C
c
^S
100
Hamming Distance
98
101
102
17
Hamming Distance
Hamming Distance
104
Parity
Parity Bit
Parity Bit
Example
Symbol
0
1
2
3
A
d
#
106
107
ASCII
011 0000
011 0001
011 0010
011 0011
100 0001
110 0100
010 0011
Even parity
0011 0000
1011 0001
1011 0010
0011 0011
0100 0001
1110 0100
1010 0011
Odd parity
1011 0000
0011 0001
0011 0010
1011 0011
1100 0001
0110 0100
0010 0011
108
18