ECE 240 Introduction to Logic Design

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± Numbers

Number Systems and Codes
Positional number systems Positional number system conversions Binary system operations Encoding techniques

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 2

Positional Number System 

General form of a number:
Most significant digit (MSB) Least significant digit (LSB)

dp-1dp-2«d0.d-1d-2..d-n
Radix Point 

The value of the number:
D !

§

p  1

d

i

™ r

i

i !  n
Radix or Base

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 3

Decimal System 

d : 0, 1, 2, . . . , 9
1453.05

r = 10
d-2

p=4,n=2

5x10-2 d-1

d3 1x103

d2 4x102

d1 5x101

d0 0x10-1 3x100

1x103 + 4x102 + 5x101 + 3x100 + 0x10-1 + 5x10-2 = 1453.05
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 4

Binary System 

b:0,1

r=2
1101.01
b-2 1x2-2

p=4,n=2

b3 1x23

b2 1x22

b-1 b1 0x21 b0 0x2-1 1x20

1x23 + 1x22 + 0x21 + 1x20 + 0x2-1 + 1x2-2 = 13.25
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 5

Exercise 

Calculate the equivalent decimal numbers:
1x2 1x20 = 1 0x2 1x2 1x21 + 0x20 = 2 + 0 = 2 1x2 1x21 + 1x20 = 2 + 1 = 3 1x2 1x2 1x22 + 0x21 + 0x20 = 4 + 0 + 0 = 4 0x2 0x2

12 102 112 1002

0x2 1x2 1x2 10112 1x23 + 0x22 + 1x21 + 1x20 = 8 + 0 + 2 + 1 = 11 1x2
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 6

Octal and Hexadecimal Numbers 

Octal number System:
r=8 d : 0, 1, 2, « , 7 

Hexadecimal number System:
r = 16 d : 0, 1, 2, «, 9, A, B, C, D, E, F 

Used for representations of long binary numbers

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 7

Binary, Decimal, Octal and Hex #s
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Octal 00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 8

Binary ± Octal Conversion 
 

Starting from the decimal point: Separate the bits into groups of three Replace each group with its corresponding Octal digit
100011110 10101 100011110 . 101012 = 100 011 110 . 101 0102 = 436 . 528

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 9

Binary - Hexadecimal Conversion 
 

Starting from the decimal point: Separate the bits into groups of four Replace each group with its corresponding Hexadecimal digit
100011110 . 101012 = 00011110 10101 0001 0001 1110 . 1010 10002 = 11E . A816

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 10

Octal - Binary Conversion 

Convert each Octal digit into its corresponding three bit string
436 . 528 =

100 011 110 . 101 0102

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 11

Hexadecimal - Binary Conversion 

Convert each Hexadecimal digit into its corresponding four bit string
A5E . C816 =

1010 0101 1110 . 1100 10002

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 12

Radix-r to Decimal Conversion

D

!

§

p  1

d

i

™ r

i

i !  n

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 13

Decimal to Radix-r Conversion 


Successive division of D by r The remainder of the long division will give the digits starting from the least significant digit

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 14

Decimal to Binary Conversion
4510 45/2 = 22 The remainder is 22/2 = 11 11/2 = 5 5/2 = 2 2/2 = 1 1/2 = 0
MSB
32 16 8 4 2

1 0 1 1 0 1

LSB

MSB

LSB
1

1

0

1

1

0

1

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 15

Exercises
Convert 5 into binary: hexadecimal: 101 5

Convert 17 into binary: hexadecimal:

10001 11 100010 22

Convert 34 into binary: hexadecimal:

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 16

Binary Addition
Binary addition table: carry in 0 0 0 0 1 1 1 1 X 0 0 1 1 0 0 1 1 Y 0 1 0 1 0 1 0 1 X+Y carry out 0 0 1 0 1 0 0 1 1 0 0 1 0 1 1 1

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 17

Example:
16 8 4 2 1

1 0 1 0 1 0 1 1 0 0 1 0 0 0 0 1

21 12 33

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 18

Binary Subtraction
Binary subtraction table: barrow in 0 0 0 0 1 1 1 1 X 0 0 1 1 0 0 1 1 Y 0 1 0 1 0 1 0 1 X-Y 0 1 1 0 1 0 1 1 barrow out 0 1 0 0 1 1 0 1

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 19

Example:
16 8 4 2 1

1 1 0 1 0 0 1 1 1 1 0 1 0 1 1

26 15 11

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 20

Representation of Negative Numbers in Binary Systems 

Signed-magnitude Representation. Two¶s-Complement Representation. One¶s-Complement Representation.  

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 21

Signed Magnitude Representation 

The MSB represents the sign bit (0 = positive, 1 = negative) The range for n-bit is from - 2n-1 ± 1 to +2n-1 ± 1. Example: n=5, Range from -15 to 15
00000 = 0 , 10000 = -0 10011 = -3 , 01100 = +12 

 

Disadvantages:
Complicated digital adders Two possible representations of zero

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 22

Two¶s Complement Representation 

The MSB represents the sign bit (0 = positive, 1 = negative) To calculate the negative number:
1. 2. 

Complement all bits of the positive number Add 1 

For n-bit number the decimal value =
B ! ¨ © ª

§

n  2

b

i

™ 2

i

i ! 0

¸ ¹ º 

b

n  1

™ 2

n  1

The range for n-bit is: n-

from -2n-1 to +2n-1

1.

Advantages: Advantages: Addition/subtraction performed directly and only one zero Disadvantage: Disadvantage: One extra negative number (not symmetric)
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 23

Two¶s Complement Example
N = 8: from -128(10000000) to 127 (01111111)

010 =

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 + 1 step 1 step 2

1 0 0 0 0 0 0 0 0 = 010

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 24

Two¶s Complement Example
64 32 16 +10010 = step 1 0 1 1 0 1 0 0 1 8 0 1 4 1 0 2 0 1 1 0 1 step 2 + 1 1 0 0 1 1 1 0 0 = -10010

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 25

One¶s Complement Representation 
 

The MSB represents the sign bit (0 = positive, 1 = negative) To calculate the negative number, complement all bits of the positive number For n-bit number the decimal value =
B
! ¨ © ª

§

n  2

b

i

™ 2

i

i ! 0

¸ ¹ º 

b

n  1

™ ( 2

n  1 

1 )

The range for n-bit is: from 2n-1 1 to +2n-1 1. nAdvantages: Advantages: Symmetry, ease of complementation. Disadvantages: Disadvantages:
Two possible representations of zero. Complicated digital adders.
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 26

One¶s-Complement Example
N = 8: form -127(10000000) to 127 (01111111) +10010 = 0 1 1 0 0 1 0 0 -10010 = 1 0 0 1 1 0 1 1 010 = 0 0 0 0 0 0 0 0 -010 = 1 1 1 1 1 1 1 1

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 27

Comparison (4-bit)
Decimal
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7

Signed Magnitude
1111 1110 1101 1100 1011 1010 1001 0000 or 1000 0001 0010 0011 0100 0101 0110 0111

One¶s Compl.
1000 1001 1010 1011 1100 1101 1110 0000 or 1111 0001 0010 0011 0100 0101 0110 0111

Two¶s Compl.
1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0010 0011 0100 0101 0110 0111

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 28

Exercise
What is the representation of +11, -11 in: +11, 5-bit signed magnitude representation +11 = 0 1 0 1 1 -11 = 1 1 0 1 1

5-bit one s complement representation +11 = 0 1 0 1 1 -11 = 1 0 1 0 0

5-bit two s complement representation +11 = 0 1 0 1 1 -11 = 1 0 1 0 1

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 29

Two¶s Complement Addition (A+B)
Use binary addition rules 2. Ignore any carry beyond the sign bit  If the range is not exceeded, addition result will be correct including the sign bit. Examples:
1.

(-2) + (-4) (-

1 1 1 0 1 1 0 0

(-3) + (+3) (0)

1 1 0 1 0 0 1 1

(-6) 1 1 0 1 0

1 0 0 0 0

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 30

Two¶s Complement Subtraction: Method 1 (a-b)
Use binary Subtraction rules 2. Ignore any borrow beyond the sign bit Example:
1.

(2) - (4) (-2)

0 0 1 0 0 1 0 0 1 1 1 0

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 31

Two¶s Complement Subtraction Method 2 (a+(-b))
Add A to the Two¶s complement of B: 1. Take the One¶s complement of B 2. Add it to A with initial carry-in i.e. 1 Initial Carry in Example: 2-4 

1 0 0 1 0

2 One s Complement of 4

+ (-2)

1 0 1 1 1 1 1 0
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 32

Coding  



Coding: Representing a set of objects by a set of strings. Code: The set of bit strings. Code Word: A particular bit string in the Code.

Examples:
Data Objects: Decimal Numbers, Characters. Nondata Objects: Machine states, Control Actions.

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 33

Binary Codes For Decimal Numbers 

To represent the 10 decimal digits, we need 4 bits.
4 bits Codes
1. 2. 3.

Examples:
BCD (8421) - Binary Coded Decimal 2421 Excess-3

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 34

Decimal Codes
Decimal BCD (8421) 0 1 2 3 4 5 6 7 8 9 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 BCD 2421 0000 0001 0010 0011 0100 1011 1100 1101 1110 1111 Excess-3 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 35

Exercise 

Codes for 517
0101 0001 0111 1011 0001 1101 1000 0100 1010

BCD: 2421: ExcessExcess-3:

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 36

Gray Code
One bit changes between two successive code words Binary Code and Gray Code (n = 3): Decimal Binary Code Gray Code 0 000 000 1 001 001 2 010 011 3 011 010 4 100 110 5 101 111 6 110 101 7 111 100
Application: Electromechanical applications. Application: The Mechanical Encoding disk. Altimeters. - is an instrument used to measure the altitude of an object above a fixed level
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 37

Binary Code to Gray Code Conversion 


Convert n bit Binary code into n bit Gray Code: Bit i of the Gray Code is obtained by comparing bits i and i+1 of the Binary Code:
Add extra 0 to the left of the Binary code If bits i and i+1 in the Binary code are the same then bit i of the Gray code is 0, else bit i is 1. 

Example:
Binary 10011 010011 1 1 01 0 Gray

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 38

Exercise
i and i+1: same 0; else, 1

Binary

11101

011101

1 0 0 1 1 Gray

Gray

1 0 0 1 1

0 1 1 1 0 1

Binary

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 39

Codes for Nondata Objects 

n objects encoded with b=log2n=log10n/log102 binary bits.

Example: 124 objects, b=7 Application: The control unit runs one device at a time.
Control Unit Enable? DEVICE Binary-coded device select Binary-

Enable? DEVICE
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 40

Enable? DEVICE

Coding for Error Control 

Bit error occurs due to noise, etc., if
0 sent is received as 1 or 1 sent is received as 0 

EDC (error detecting codes) to detect bit errors ECC (error correcting codes) to correct bit errors 

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 41

EDC: Repetition-2 Code
To send: send: If we receive 10110

1100111100 1000001101

we detect two errors but miss one 

Detects any one bit error in a 2-bit block, but will miss two
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 42

ECC: Repetition-3 Code
To send: send: If we receive 10110

111000111111000 110000100001001

we correct two and miss two. 

Detects any one bit error in a 3-bit block, but will miss any two or three
Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 43

Parity-bit EDCs
Sender
To send m bits, b1, b2, , bm.

Receiver
s=0, if s=0, then 0 (or 2 or 4 or errors occurred, no error. if s=1, then 1 (or 3 or 5 or s=1, errors occurred. compute s = r1‡ r2 ‡ When r1, r2, b1, b2, , b m, p
Information Bits Even-parity Code Odd-parity Code

) bit ) bit

Send m+1 bits, b1, b2, , bm, p, where p = b1 ‡ b2 ‡ ‡ bm (b1‡ b2 ‡
‡ bm ‡ p = 0)

‡ rm ‡ rm+1

, rm, rm+1 is received

P(2 or 4 or

errors)= P (undetected errors) small enough for independent bit errors

T a b le 2 - 1 3 Distance-2 codes with three information bits.

000 001 010 011 100 101 111

000 0 001 1 010 1 011 0 100 1 101 0 111 1

000 1 001 0 010 0 011 1 100 0 101 1 110 1 111 0

Synopsys University Courseware ± ECE 240 110 110 0 Lecture Set 2 ± 44

Error-Detection 

Error detection: use a dictionary of code words that is a subset of the 2n possible code words
A failure occurs when an invalid code word is sent

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 45

Summary 

Binary forms used in digital systems
Positive/Negative numbers, addition/subtraction Arithmetic operations performed directly on negative numbers represented in Two¶s complement.   

Hexadecimal numbers are used for shorthand representation of binary numbers. Decimal numbers, characters, and actions encoded into binary strings. Error-detecting and error-correcting codes use extra bits.

Synopsys University Courseware ± ECE 240 Lecture Set 2 ± 46