Sie sind auf Seite 1von 18

# ELE 107-Week 2: Number Systems & Binary Codes

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

## As another example, consider the representation

of the number 11, which has no associated units.
Some different ways of representing 11 might be:
11 , XI , eleven , 11.00 ,
The choices depend on the context. The two
representations 11 and 11.00 tell us that there are
also different types of numbers: whole numbers
and fractions.

## It clearly refers to a number. It involves a numeric

measure of quantity, and requires some choice of
units.
So, we might say the fuel capacity is: 88,828
gallons, or 336,250 liters, or 606,701 pounds.

## Each representation describes the same amount

of fuel capacity, but because different units are
used, different numbers become involved.
3

Number Systems

## ELE 107 Dr. Derya Altunay

Number Systems
In Roman number system a symbol always
represents the same weight:

## Number systems may be symbolic,

such as the Roman number system, or
they may be weighted-positional, such as the Arabic
number system we normally use.

I = 1 , V = 5 , X = 10 , L = 50 , C = 100
D = 500 , M = 1000.

## If a symbol is repeated or lies to the right of

another symbol, then the value of the symbol is
If a symbol is repeated or lies to the left of a
higher-valued symbol, then the value of the
symbol is subtractive. (XXC is ..).

number systems.

Number Systems

## As an example, consider the description the

fuel capacity of an Airbus A380.

Number Systems

Number Systems

## In a weighted-positional number system, the

value of a particular digit depends on its
position in the sequence of digits relative to a
Number is a concept independent of its representation; any given number can be zero, an
integer, fractional, irrational, transcendental,
negative, prime, or complex depending on the
underlying base system.
7

Number Systems

(734)14

## 7142 + 3141 + 4140

4196 + 314 + 71
78410 + 4210 + 710

7196 + 314 + 41
137210 + 4210 + 410

(833)10

7100 + 310 + 41
700 + 30 + 4

437

734

9

Number Systems

## ELE 107 Dr. Derya Altunay

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

## (N)r = xn xn-1 xn-2 x1 x0 . x-1 x-2 x-m

point

where,
r is the base of the number N,
xn is the most significant digit (MSD),
x-m is the least significant digit (LSD).

4100 + 310 + 71
400 + 30 + 7

## A weighted-positional number system can be

constructed around any integral base. Most
A number in any weighted-positional number
system can be represented using a string of
digits (symbols) :

(1418)10

734

Number Systems

(437)14

437

## There are r digits (symbols) in a base-r number system:

{ 0, 1, 2 , , r-1 }
The position values (weights) are powers of the base.
Each digit has a value relative to its position in the
number.
Any number greater than r can be described by a
combination these digits.
11

12

## ELE 107-Week 2: Number Systems & Binary Codes

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

## (N)r = xn xn-1 xn-2 x1 x0 . x-1 x-2 x-m

= xn r n + +x1r1 +x0r0 +x-1 r -1 + x-m r -m
= (M)10

13

## Uses two symbols: 0, and 1. (Each is called a bit for

binary digit)
The weights of each position are powers of two.
A number such as (101.01)2 will be expanded as:
2
22
1

-1 -2
10 -1 10 -2
3
5

15

0
20
1

-1 -2
2 -1 2 -2
0
1

16

## Numbers with Different Bases

Number Systems

Decimal
Decimal: Base 10
00
Binary: Base 2
01
02
Octal: Base 8
03
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

## (1234)10 = 1 x 103 + 2 x 102 + 3 x 101 + 4 x 100

(1010)2 = 1 x 23 + 0 x 22 + 1 x 21 + 0 x 20
=1x8 + 0x4 + 1x2 + 0x1
= 810 + 210 = (10)10

1
21
0

## = (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2)

= 5.25 in the decimal system.

## = (6 x 102) + (4 x 101) + (2 x 100) + (3 x 10-1) + (5 x 10-2)

= 642.35 in the decimal system.

## General formula for converting

a number from base r to decimal
(xk is the kth digit of the number)

14

## Uses ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

The positional values (weights) of each position are
powers of ten.
A number such as (642.35 )10 will be expanded as:
0
100
2

## When you run out of

digits, make it a zero and
increment the next place
value to the left.
11two becomes 100two

Binary Numbers

1
101
4

## Each number has a

unique representation.
Counting:

Decimal Numbers

2
102
6

Binary

Decimal

## A number in any weighted-positional number

system can be easily converted to an equivalent
decimal number by expressing the number as a
polynomial in powers of the radix:

D = xk r k
k = -m

17

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

## Numbers with Different Bases

It takes 3 binary digits Decimal
00
(bits) to represent the
01
numbers 0-7
02
Each group of 3 bits
03
04
corresponds to exactly
05
one octal digit
06
It takes 4 (bits) to
07
represent the numbers
08
09
0-15
10
Each group of 4 bits
11
corresponds to exactly
12
one hex digit
13

Binary
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
14
1110
15
1111

Octal Numbers

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

## ELE 107 Dr. Derya Altunay

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

## ELE 107 Dr. Derya Altunay

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

## (1011.11)2 = 123 + 022 + 121 + 120 + 12-1 +

12-2
= 8 + 0 + 2 + 1 + + = (11.75)10

Repeated
Subtraction

## 1. Find the greatest integer that is a power of 2 and

when subtracted from N it yields a positive
difference N1
2. Place a 1 in the MSB
3. Repeat Step 1, starting from N1 and finding
difference N2 . Place a 1 in the corresponding bit.
Stop when the difference is zero.

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

## = (6 x 162) + (4 x 161) + (15 x 160) + (3 x 16-1) + (0 x 16-2)

= (1615.1875)10 in the decimal system.
ELE 107 Dr. Derya Altunay

-1 -2
8 -1 8 -2
3
0

## = (6 x 82) + (4 x 81) + (2 x 80) + (3 x 8-1) + (0 x 8-2)

= (418.375)10 in the decimal system.

1010011

-1 -2
16 -1 16 -2
3

2
82
6

## Each bit in a binary number

refers to a power of two:

## Uses sixteen symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A,

B, C, D , E and F.
The positional values (weights) of each position are
powers of sixteen.
A number such as (64F.30 )16 will be expanded as:
1
161

## Uses eight symbols: 0, 1, 2, 3, 4, 5, 6, and 7.

The positional values (weights) of each position are
powers of eight.
A number such as (642.30 )8 will be expanded as:

Binary-to-Decimal Conversion

2
162

23

24

## ELE 107-Week 2: Number Systems & Binary Codes

Decimal-to-Binary Conversion

Decimal-to-Binary Conversion

Repeated
Subtraction

## Subtract largest power of two N

25 - 24 = 25 - 16 = 9
Subtract largest power of two Difference
9 - 23 = 9 - 8 = 1
Subtract largest power of two Difference
1 - 20 = 1 - 1 = 0
Now, we see (25)10 = 24 + 23 + 20 = (1 1 0 0 1)2

## 1. Divide the integer successively by 2

until you get to zero
2. Read the remainders in reverse order.

Repeated
Subtraction

+ 23 + + 21 + 20
1 0 1 1)2
26

## ELE 107 Dr. Derya Altunay

Decimal-to-Binary Conversion
Let N be a decimal integer:

512 = 29
128 = 27
64 = 26
8 = 23
2 = 21
1 = 20

## 715 512 = 203 = N1

203 128 = 75 = N2
75 64 = 11 = N3
11 8 = 3 = N4
3 2 = 1 = N5
1 1 = 0 = N6
(715)10 = 29 +
27 + 26
=(1 0 1 1 0

25

## ELE 107 Dr. Derya Altunay

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
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

## Each octal digit is represented by three bits.

3 bits per group starting from the radix point.

## Each hex digit is represented by four bits.

4 bits per group starting from the radix point.

(3

( 2

7 . 1

5 )8

(2

( 2

6 . 5

4 )8
29

C .

D )16

B

3.

C )16
30

## Decimal to any radix r

Go through decimal:
Hex Decimal Octal
Octal Decimal Hex

## Conversion from decimal to radix r system is

carried out by separating the number into its
integer and fraction parts and converting
each part separately.
Divide the integer successively by r and collect
Multiply the fraction successively by r , keep
track of the integral part until the fraction

Hex Binary Octal
Octal Binary Hex

31

## ELE 107 Dr. Derya Altunay

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

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:

down

## 0.6875 x 8 = 5.500 (m.s.d)

0.500 x 8 = 4.000 (l.s.d)
33

## 0.78125 x 16 = 12.5 (m.s.d) (12 = C)

0.5 x 16
= 8.0 (l.s.d)
ELE 107 Dr. Derya Altunay

up

down

## ELE 107 Dr. Derya Altunay

(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

## ELE 107 Dr. Derya Altunay

34

Notes on Fractions

up

## Decimal point in base 10

Binary point in base 2
Octal point in base 8
Hex point in base 16

separately

down
35

36

## ELE 107-Week 2: Number Systems & Binary Codes

Notes on Fractions

Notes on Fractions

## Digit to the left is a unit digit in every base

(Base)0 is always 1 regardless of the base

## Effect: multiplies the number by the base number

Example: (427.6)10

(4276)10
Shift the radix point one place to the left

## No exact relationship between fractional

numbers in different number bases

## Exact conversion may not be possible

Example: (427.6)10

37

(42.76)10

38

## ELE 107 Dr. Derya Altunay

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

## ELE 107 Dr. Derya Altunay

Notes on Fractions

0.125

## ELE 107 Dr. Derya Altunay

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

## ELE 107-Week 2: Number Systems & Binary Codes

Notes on Fractions

Notes on Fractions

## (0.975)10 = (?)8 = (0.76314)8

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

## No general relationship between fractions of

types 1/10k and 1/2k
A number representable in decimal may not be
representable in binary
The converse is true: all fractions of the form 1/2k
can be represented in decimal

## Fractional conversions from one base to

another are stopped
If there is a rational solution or
When the desired accuracy is attained

(repeates!)
43

## ELE 107 Dr. Derya Altunay

Number Ranges

Data Representation
When we communicate with each other, the information
is represented in an understandable notation, e.g., we use

## Assume a computer is processing 16-bit

unsigned integers and fractions:
Integer part (16-bit)

## Digits to represent numbers

Letters to represent text

## When we communicate with a computer:

Text and numbers are entered through keyboard/mouse
Text, numbers, and images are displayed on the screen

216-1

Integer range:
0 to
(0 to 65535)
16
Fraction range:
0 to (2 -1) / 216
(0 to 65535/65536 = 0.9999847412)

## This may be referred to as an external representation.

How do humans store the information internally?
How do computers store the information internally?
45

## ELE 107 Dr. Derya Altunay

Data Representation
Humans:

Computers:

## The five types of data/information the

computer commonly manipulates:

Text, numbers,
sounds

???
Text, numbers,
images, sounds

Text, numbers,
images, sounds

Numeric
Character
Visual
Audio
Instructional

## First, the data must be transformed (converted)

into an acceptable representation that the
computer will accept.

Binary Numbers
ELE 107 Dr. Derya Altunay

46

Data Representation

Internal

Text, numbers,
images, sounds

44

47

48

Binary Systems

Binary Systems

## The system in which all computer data is

represented and manipulated is called the
binary system.
All modern computers work with a system of
numbers called binary numbers.

## Binary circuits: Electronic devices are

cheapest and function most reliably if they
assume only two states.

Open circuit

Closed circuit
49

## ELE 107 Dr. Derya Altunay

Binary Systems
Binary systems have two
values
Zero and One

## Binary numbers are easy

to represent using
physical phenomena
All numbers can be
represented in binary as
well as in any other base

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

## is the smallest unit of

information
can have two values
can represent numbers,
codes, or instructions

## Think of these values as

switches: yes and no, black
and white, high and low, or
ON and OFF
52

## ELE 107 Dr. Derya Altunay

Bits as Instructions

Off/On Switches

## Larger chunks of information are stored by

grouping bits as units

## The computer can represent data by

constructing combinations of off or on
switches.

## The computer stores programs as collections

of bits.
For instance, 01101010 might instruct the

OFF

or

ON

## Other bit instructions might include where

to find numbers stored in memory or where
to store them.
ELE 107 Dr. Derya Altunay

53

54

Zero or One?

The Bit

## The binary system can also be represented by

the digits zero and one.

or

one bit
two bits

three bits

## Zero (off) and one (on) make up the two

digits in the binary system.
55

Each 0 or 1
in the binary
system is
called a bit.

56

## ELE 107 Dr. Derya Altunay

Representation of Numbers

The Byte
A group of 8 bits is called a byte.

## The three-light system:

Has eight possible
combinations on and off.
Could be used to indicate the
numbers 0, 1, 2, 3, 4, 5, 6, 7.
0 = 000 4 = 100
1 = 001 5 = 101
2 = 010 6 = 110
3 = 011 7 = 111

= J

Storing Bytes

58

Computer Word

## Storage and memory capacity is expressed

in the number of bytes they can hold:

## A computer word is defined as the number of

bits that constitute a common unit of data.
Word length varies by computer.
For example:

## 1 kilobyte (KB) = 210 or 1024 bytes (1K)

1 megabyte (MB) = 220 or 1,048,576 bytes
1 gigabyte (GB) = 230 or 1,073,741,824 bytes
1 terabyte (TB) = 240 or about one million MB
1 petabyte (PB) = 250 or about one million GB

## Each byte represents one character of data

(a letter, digit, or special character).

57

## 8 bits = 1 byte = one word length

32 bits = 4 bytes = one word length
64 bits = 8 bytes = one word length

## Different computers use different numbers of

bits: Intel Pentium 32 bits , Intel Itanium 64 bits
59

60

10

Bits as Codes

## A code for determining which group of bits

represent which characters on a keyboard is
called ASCII.
ASCII has been adopted, as the standard, by the
U.S. government and is found in a variety of
computers.
0 1 0 0 1 0 1 0
ASCII-8 code

## ASCII - American Standard

Code for Information Interchange
Most widely used code,
represents each character as a
unique 8-bit code.

Keyboard character

61

62

## Binary Codes for Decimals

The binary number system is the most natural
system for the computer, but people are
accustomed to the decimal system.
Computers work internally with binary
numbers, the I/O generally uses decimal
numbers (human-interface).

Binary Codes
ELE 107
Computers and Programming I

63

## Binary Codes for Decimals

Terminology
A codeword (encoding) is a symbolic
representation based on the binary
alphabet, that is a sequence of 1s and 0s.

## So, convert decimal numbers to binary,

perform operations in binary, and convert
the binary results back to decimal.
Therefore, we have to store the decimal
numbers in the computer in a way that they
can be converted to binary.
We represent the decimal digits by a
binary code.
ELE 107 Dr. Derya Altunay

64

## The length of the codeword is the number

of bits in the codeword. For example,
0110010 has a length of seven.

65

66

11

## ELE 107-Week 2: Number Systems & Binary Codes

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}.

## A code is a set of codewords. For example,

the set {110, 001, 101, 011, 111 } is a code
that has five codewords.
Because each codeword has the same
length, this is a fixed-length code.
Variable-length codes have codewords
with different lengths.

67

Terminology

BCD

## If m symbols are to be encoded then 2n m

must be satisfied.
A code that uses n-bit strings need not contain
2n valid codewords.
At least four bits are necessary to represent
the ten decimal digits (6 are unused) .
There are many different ways to choose ten
4-bit codewords.

## The most popular and natural decimal code is

called binary-coded decimal (BCD).
BCD numbers are decimal numbers even
though they are represented in bits.
Each decimal digit is represented by a 4-bit
unsigned binary number.
Multiple digit decimal numbers are represented
by coding each of the digits.
69

70

BCD

BCD
Decimal Symbol
0
1
2
3
4
5
6
7
8
9

## BCD is different from converting a decimal

number to binary.
For example (97)10 , when converted to binary,
is (1100001)2.
97 when represented in BCD is (1001 0111)BCD.
Although BCD requires more bits, it is easier to
understand and interpret.

68

71

BCD Digit
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
72

12

## ELE 107-Week 2: Number Systems & Binary Codes

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

## The 2421 code and the Excess-3 (XS-3) code

are both examples of self-complementing
codes.
Self-complementing property:The 9s
complement of each digit (9-d) is obtained by
complementing each bit in the codeword.
Self-complementing property is useful when
performing operations such as subtraction.

## The 2421 code is a weighted code.

The bits are multiplied by indicated weights
and the sum gives the decimal digit.
The XS-3 code is a nonweighted code.
XS-3 code is obtained from the
corresponding BCD code added to 3.
XS-3 code is useful in decimal subtraction.

75

76

Gray Code

## The biquinary code uses seven bits for each

decimal digit.
The first two bits indicate whether the digit
is in the range 0-4 or 5-9.
The last five bits indicate which of the five
numbers in the selected range is
represented.
Any advantage using more than the minimum
number of bits in a code ?

## Sometimes it is desirable to use codes in which

all successive codewords differ in only one bit
(cyclic codes).
An important cyclic code is the Gray code.
Continuous, or analog, information is converted
into digital form by means of an A/D converter.
The Gray code, is sometimes used for the
converted digital data.
Used in electromechanical applications of
digital systems, such as copy machines, brake
systems, machine tools, etc.

77

78

13

Gray Code

Gray Code

## The Gray code is a code in which only one bit of a

codeword changes between each pair of successive
codewords.
This is useful when the analog signal is on the
border between two of the binary coded values.
For example, switching from 7 (0111) to 8 (1000)
requires four bits to be changed simultaneously. If
this does not happen, then various illegitimate
numbers could be momentarily generated during
the transition.
Using the Gray code keeps the value from being
misrepresented in such cases.

## Gray code counters are

sometimes used to provide
the timing sequences that
control the operations in a
digital system.
The Gray code is also an
example of a reflected
code ; i.e., the n-bit code
can be obtained by reflecting
the (n -1)st-bit code.
79

Gray Code
Binary to Gray :

## Data Types: Alphanumeric

Alphanumeric:

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

## Both entered as ordinary characters

Computer converts into numbers for calculation

bi = g n g n 1 L g i

programmer

( 0 i n 1)

## Treated as characters if processed as text

Examples: Phone numbers, ZIP codes

(1 0 1 1 0 1)GRAY = (1 1 0 1 1 0)2
ELE 107 Dr. Derya Altunay

81

Alphanumeric Codes

## ELE 107 Dr. Derya Altunay

82

Representing Characters
ASCII : most widely used coding scheme
Unicode : developed for worldwide use

## Arbitrary choice of bits to represent

characters
Standard (consistency): input and output device
must recognize same code
Value of binary number representing character
corresponds to placement in the alphabet

## ASCII file often used as a synonym for text

file (Although a text file can be encoded in
ASCII code, or Unicode)

83

84

14

ASCII

ASCII

## Developed by ANSI (American National

Standards Institute)
American Standard Code for Information
Interchange.
The standard alphanumeric binary code
Represents

## ASCII is an example of a fixed-size code with

a code length of seven
Basic ASCII uses 7 bits to code 128 characters
Most computers manipulate the 7-bit ASCII
code as a byte with the m.s.b set to 0.
This extra bit is used for specific purposes:

## Latin alphabet, Arabic numerals, standard

punctuation characters
Plus small set of accents and other European
special characters

## An additional 128 8-bit characters with the m.s.b

set to 1.
As a parity bit (check for memory/communication
errors)
85

ASCII

ASCII

87

88

## Two subsets in the ASCII character set: the

control characters and the printable characters.
The control characters include the first 32
characters and the last character (delete).
The remaining characters are the printable
characters.
The printable characters can be generated by
typing the appropriate keys on keyboards.
The control characters can be generated by
holding down the control key while typing a
single character.
ELE 107 Dr. Derya Altunay

86

## ELE 107 Dr. Derya Altunay

89

Decimal
0 31

ASCII
Invisible (control characters)

32 47
48 - 57
58 64

## Punctuation, mathematical operations

Characters 0 9
Comparators and other miscellaneous characters : ; ? @

65 - 90
91 96
97 122
123 127

## Alphabetic (upper case A - Z)

More miscellaneous characters [ \ ] ^ _ '
Alphabetic (lower case a - z)
More miscellaneous characters { | } ~ DEL

90

15

Decoding

Unicode

## Since ASCII is a fixed-length code, it is easy

to decode sequences of encoded characters.
Start breaking the sequence into subsequences
consisting of 7 bits.
Then match each subsequence to a character
using the ASCII table.
Decode the ASCII string :
10010001100101110110011011001101111

## Most common 16-bit form represents 65,536 symbols.

ASCII Latin-I subset of Unicode

## Allows software modifications for local languages

Unicode used by Web browsers, Java, most software.

## Multilingual: defines codes for

Nearly every character-based alphabet
Large set of ideographs for Chinese, Japanese and Korean
Composite characters for vowels and syllabic clusters
required by some languages

91

92

## U+2601 (alt-09729) CLOUD = cloudy weather

U+2602 (alt-09730) UMBRELLA = rainy weather
U+2603 (alt-09731) SNOWMAN = snowy weather

U+221E INFINITY

93

94

for Unicode

## Chess symbols in Unicode

U+2654 (alt-09812) WHITE CHESS KING
U+2655 (alt-09813) WHITE CHESS QUEEN
U+2656 (alt-09814) WHITE CHESS ROOK
U+2657 (alt-09815) WHITE CHESS BISHOP
U+2658 (alt-09816) WHITE CHESS KNIGHT
U+2659 (alt-09817) WHITE CHESS PAWN

95

96

16

## ELE 107-Week 2: Number Systems & Binary Codes

Character Encodings

Error Detection/Correction

## Characters are symbols that we use in written

communication.
Machine cannot provide a direct representation
for every character we use (There are many
symbols and new symbols are created).
Each machine provides a limited set of
characters called the character set of the
machine.
Now almost every manufacturer uses the
ASCII character set.

## The storage or transmission of an encoded value can

incorrectly change the value.
We can use an error detection or an error correction
strategy to limit the scope of that change.
In error detection, the goal is to detect errors that
occur. The detected errors cannot be corrected, but
can prompt the data to be retransmitted.
The goal of error correction is to correct any errors
that occur during transmission.
Error correction is frequently called error masking
because errors are not visible to any part of the
97

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
4
5
single bit is
flipped during
6
transmission.

## To simplify the presentation, only fixed-length

codes will be considered.
We only consider errors that change individual
bits.
We ignore the possibility of inserting or
deleting bits.
Changes to bits are frequently called bit flips
because the change flips the bit from 0 to 1 or
from 1 to 0.
ELE 107 Dr. Derya Altunay

99

Hamming Distance

pattern
101 0011
101 0010
101 0001
101 0111
101 1011
100 0011
110 0011
001 0011

symbol
S
R
Q
W
[
C
c
^S
100

Hamming Distance

## The Hamming distance defines a distance between

two codewords, you count the number of bits in
the first codeword that need to be changed to result
in the second codeword.

## What is the Hamming distance between

1011001 and 1011010?
To convert the first pattern to the second , we need to
change the first and the second bits in the first pattern.
The Hamming distance between the two patterns is 2.
ELE 107 Dr. Derya Altunay

98

101

## We generalize the Hamming distance to a code by

considering the elements of the code in a pair-wise
fashion.
Given a fixed-length code, the Hamming distance for
the code is the minimum distance between any two
codewords in the code.
What is the Hamming distance of the following code?
{ 1010, 1101, 0110 }
dist (1010, 1101) = 3
dist (1010, 0110) = 2
The Hamming distance is 2.
dist (1101, 0110) = 3
ELE 107 Dr. Derya Altunay

102

17

Hamming Distance

Hamming Distance

## The Hamming distance for the code reflects the

degree of redundancy in the code.
If a code has a Hamming distance of two,
changing a single bit in any of the codewords
will result in a bit pattern that is not in the code.
Thus, we can decide if an error introduced a
single bit flip.
A code with a minimum distance of 2c + d + 1
can correct up to c bit errors and detect up to

## 10111011 and 10010011 is ?

10111011
10010011 it is 2
91738254 and 92337254 is ?
91738254
92337254 it is 3
COMPUTATION and CALCULATION is ?
COMPUTATION
CALCULATION it is 4
103

104

Parity

Parity Bit

## Parity provides a simple way to ensure that the

Hamming distance of a code is at least two.
The parity of a binary pattern is determined by
counting the number of 1s in the pattern.
If the number of 1s is even, then the pattern has even
parity ; otherwise, the pattern has odd parity.
What is the parity of the pattern 1010111?

## To ensure that every codeword has the same

parity, we add a bit called the parity bit, to each
codeword.
Given a codeword, we set the parity bit to 1 or 0
to make sure that the resulting bit pattern has the
desired parity.
Then we add a parity bit to the ASCII code, the
parity bit is the 8th bit in the codeword.

## Because the pattern has five 1s, it has odd parity.

If every codeword in a code has the same parity, the
code must have a Hamming distance of at least two.
105

Parity Bit

Example
Symbol
0
1
2
3
A
d
#

## The parity bit is extremely important when two

computers exchange information.
The sender and the receiver must agree on the
type of parity.
The simple parity scheme provides us with
enough information to detect a single error, but
not enough to correct it.

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