You are on page 1of 54

1

Introduction

Dr. Abdul Sattar Malik


Overview

 Digital Systems, Computers, and Beyond


 Information Representation
 Number Systems [binary, octal and hexadecimal]
 Arithmetic Operations
 Base Conversion
 Decimal Codes
 Alphanumeric Codes
 Parity Bit
 Gray Codes
DIGITAL & COMPUTER SYSTEMS - Digital System

 Takes a set of discrete information inputs and discrete


internal information (system state) and generates a set of
discrete information outputs.

Discrete Discrete
Inputs Information
Processing Discrete
System Outputs

System State
Types of Digital Systems

 No state present
 Combinational Logic System
 Output = Function(Input)
 State present
 State updated at discrete times
 Synchronous Sequential System
 State updated at any time
 Asynchronous Sequential System
 State = Function (State, Input)
 Output = Function (State) or Function (State, Input)
Digital System Example

A Digital Counter (e. g., odometer)

Count Up
Reset 0 0 1 3 5 6 4

Inputs: Count Up, Reset


Outputs: Visual Display
State: "Value" of stored digits
Digital Computer Example

Memory

Control
CPU unit Datapath

Inputs:
Outputs: LCD
keyboard,
screen,
mouse, Input/Output wireless,
wireless,
speakers
microphone
And Beyond – Embedded Systems

 Computers as integral parts of other products


 Examples of embedded computers
 Microcomputers
 Microcontrollers
 Digital signal processors
 Examples of Embedded Systems Applications
 Cell phones
 Automobiles
 Video games
 Copiers
 Dishwashers
 Flat Panel TVs
 Global Positioning Systems

Chapter 1 8
INFORMATION REPRESENTATION - Signals

 Information variables represented by physical quantities.


 For digital systems, the variables take on discrete values.
 Two level, or binary values are the most prevalent values
in digital systems.
 Binary values are represented abstractly by:
 digits 0 and 1
 words (symbols) False (F) and True (T)
 words (symbols) Low (L) and High (H)
 and words On and Off.
 Binary values are represented by values or ranges of
values of physical quantities

Chapter 1 9
Signal Examples Over Time

Time

Continuous
Analog in value &
time
Digital
Discrete in
Asynchronous value &
continuous
in time
Synchronous Discrete in
value & time

Chapter 1 10
NUMBER SYSTEMS – Representation

 Positive radix, positional number systems


 A number with radix r is represented by a string of digits:
An - 1 An - 2 … A1 A0 . A- 1 A- 2 … A- m + 1 A- m
in which 0 Ai < r and . is the radix point.
 The string of digits represents the power series:

i=n-1 j=-1
(Number)r =
 Ai r + i
 Aj r j

( )( )
i=0 j=-m
(Integer Portion) + (Fraction Portion)

Chapter 1 11
Number Systems – Examples

General Decimal Binary


Radix (Base) r 10 2
Digits 0 => r - 1 0 => 9 0 => 1
0 r0 1 1
1 r1 10 2
2 r2 100 4
3 r3 1000 8
Powers of 4 r4 10,000 16
Radix 5 r5 100,000 32
-1 r -1 0.1 0.5
-2 r -2 0.01 0.25
-3 r -3 0.001 0.125
-4 r -4 0.0001 0.0625
-5 r -5 0.00001 0.03125

Chapter 1 12
Decimal Number System
 Base (also called radix) = 10
 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
 Digit Position
 Integer & fraction 2 1 0 -1 -2
 Digit Weight
Position 5 1 2 7 4
 Weight = (Base)
 Magnitude
100 10 1 0.1 0.01
 Sum of “Digit x Weight”
 Formal Notation

500 10 2 0.7 0.04

d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2

(512.74)10
13 /
45
Octal Number System
 Base = 8
 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
 Weights
Position
 Weight = (Base) 64 8 1 1/8 1/64
 Magnitude
5 1 2 7 4
 Sum of “Digit x Weight”
2 1 0 -1 -2
 Formal Notation
5 *82+1 *81+2 *80+7 *8-1+4 *8-2
=(330.9375)10

(512.74)8

14 /
45
Binary Number System
 Base = 2
 2 digits { 0, 1 }, called binary digits or “bits”
 Weights
Position 4 2 1 1/2 1/4
 Weight = (Base)
 Magnitude 1 0 1 0 1
 Sum of “Bit x Weight”
2 1 0 -1 -2
 Formal Notation
1 *22+0 *21+1 *20+0 *2-1+1 *2-2
 Groups of bits 4 bits = Nibble =(5.25)10
8 bits = Byte
(101.01)2
1011

11000101
15 /
45
Hexadecimal Number System
 Base = 16
 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }
 Weights
Position
 Weight = (Base) 256 16 1 1/16 1/256

 Magnitude
1 E 5 7 A
 Sum of “Digit x Weight”
2 1 0 -1 -2
 Formal Notation
1 *162+14 *161+5 *160+7 *16-1+10 *16-2
=(485.4765625)10

(1E5.7A)16

16 /
45
The Power of 2

n 2n n 2n
0 20=1 8 28=256
1 21=2 9 29=512
2 22=4 10 210=1024 Kilo

3 23=8 11 211=2048
4 24=16 12 212=4096
5 25=32 20 220=1M Mega

6 26=64 30 230=1G Giga

7 27=128 40 240=1T Tera


17 /
45
Addition
 Decimal Addition

1 1 Carry
5 5
+ 5 5

1 1 0
= Ten ≥ Base
 Subtract a Base

18 /
45
Binary Addition
 Column Addition

1 1 1 1 1 1
1 1 1 1 0 1 = 61
+ 1 0 1 1 1 = 23

1 0 1 0 1 0 0 = 84

≥ (2)10

19 /
45
Binary Subtraction
 Borrow a “Base” when needed

1 2 = (10)2
0 2 2 0 0 2
1 0 0 1 1 0 1 = 77
− 1 0 1 1 1 = 23

0 1 1 0 1 1 0 = 54

20 /
45
Binary Multiplication
 Bit by bit

1 0 1 1 1
x 1 0 1 0
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1

1 1 1 0 0 1 1 0
21 /
45
Number Base Conversions
Evaluate
Magnitude
Octal
(Base 8)

Evaluate
Magnitude
Decimal Binary
(Base 10) (Base 2)

Hexadecimal
(Base 16)
Evaluate
22 /
Magnitude 45
Decimal (Integer) to Binary Conversion

 Divide the number by the ‘Base’ (=2)


 Take the remainder (either 0 or 1) as a coefficient
 Take the quotient and repeat the division

Example: (13)10
Quotient Remainder Coefficient
13 /2= 6 1 a0 = 1
6 /2= 3 0 a1 = 0
3 /2= 1 1 a2 = 1
1 /2= 0 1 a3 = 1
Answer: (13)10 = (a3 a2 a1 a0)2 = (1101)2

MSB LSB

23 /
45
Decimal (Fraction) to Binary Conversion

 Multiply the number by the ‘Base’ (=2)


 Take the integer (either 0 or 1) as a coefficient
 Take the resultant fraction and repeat the division

Example: (0.625)10
Integer Fraction Coefficient
0.625 × 2 = 1 . 25 a-1 = 1
0.25 × 2 = 0 . 5 a-2 = 0
0.5 ×2= 1 . 0 a-3 = 1
Answer: (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2

MSB LSB
24 /
45
Decimal to Octal Conversion
Example: (175)10
Quotient Remainder Coefficient
175 / 8 = 21 7 a0 = 7
21 / 8 = 2 5 a1 = 5
2 /8= 0 2 a2 = 2
Answer: (175)10 = (a2 a1 a0)8 = (257)8

Example: (0.3125)10
Integer Fraction Coefficient
0.3125 * 8 = 2 . 5 a-1 = 2
0.5 *8= 4 . 0 a-2 = 4
Answer: (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8

25 /
45
Binary − Octal Conversion
 8 = 23 Octal Binary
 Each group of 3 bits represents an octal
0 000
digit
1 001
2 010
Assume Zeros
Example: 3 011
( 1 0 1 1 0 . 0 1 )2 4 100
5 101
6 110
( 2 6 . 2 )8 7 111

Works both ways (Binary to Octal & Octal to Binary)


26 /
45
Binary − Hexadecimal Conversion
 16 = 24 Hex Binary
0 0000
 Each group of 4 bits represents a
1 0001
hexadecimal digit 2 0010
3 0011
4 0100
5 0101
Assume Zeros 6 0110
Example:
7 0111
( 1 0 1 1 0 . 0 1 )2 8
9
1000
1001
A 1010
B 1011
C 1100
D 1101
(1 6 . 4 )16 E 1110
F 1111
Works both ways (Binary to Hex & Hex to Binary)
27 /
45
Octal − Hexadecimal Conversion
 Convert to Binary as an intermediate step

Example:
( 2 6 . 2 )8

Assume Zeros Assume Zeros

( 0 1 0 1 1 0 . 0 1 0 )2

(1 6 . 4 )16

Works both ways (Octal to Hex & Hex to Octal)


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

29 /
45
Complements
 1’s Complement (Diminished Radix Complement)
 All ‘0’s become ‘1’s
 All ‘1’s become ‘0’s
Example (10110000)2
 (01001111)2
If you add a number and its 1’s complement …

10110000
+ 01001111

11111111
30 /
45
Complements
 2’s Complement (Radix Complement)
 Take 1’s complement then add 1
 Toggle all bits to the left of the first ‘1’ from the right
OR
Example:
Number:
1’s Comp.:
10110000 10110000
01001111
+ 1

01010000 01010000

31 /
45
Negative Numbers
 Computers Represent Information in ‘0’s and ‘1’s
 ‘+’ and ‘−’ signs have to be represented in ‘0’s and ‘1’s
 3 Systems
 Signed Magnitude
 1’s Complement
 2’s Complement
All three use the left-most bit to represent the sign:
 ‘0’  positive
 ‘1’  negative

32 /
45
Signed Magnitude Representation
 Magnitude is magnitude, does not change with sign

S  (Magnitude
(+3) 0 0 1 1 )2 (Binary)
10
(−3)10  ( 1 0 1 1 )2

 Can’t include the sign bit in ‘Addition’


Sign Magnitude

0 0 1 1  (+3)10
+ 1 0 1 1  (−3)10

1 1 1 0  (−6)10
33 /
45
1’s Complement Representation
 Positive numbers are represented in “Binary”

0 Magnitude (Binary)
 Negative numbers are represented in “1’s Comp.”

(+3)10  (0 011)2
1 Code (1’s Comp.)
(−3)10  (1 100)2
 There are 2 representations for ‘0’
(+0)10  (0 000)2
(−0)10  (1 111)2

34 /
45
1’s Complement Range
 4-Bit Representation Decimal 1’s Comp.
4 +7 0111
2 = 16 Combinations
+6 0110
− 7 ≤ Number ≤ + 7 +5 0101
3 3
−2 +1 ≤ Number ≤ +2 − 1 +4 0100
 n-Bit Representation +3 0011
n−1 n−1 +2 0010
−2 +1 ≤ Number ≤ +2 − 1 +1 0001
+0 0000
−0 1111
−1 1110
−2 1101
−3 1100
−4 1011
−5 1010
−6 1001
−7 1000
35 /
45
2’s Complement Representation
 Positive numbers are represented in “Binary”

0 Magnitude (Binary)
 Negative numbers are represented in “2’s Comp.”

(+3)10  (0 011)2
1 Code (2’s Comp.)
(−3)10  (1 101)2
 There is 1 representation for ‘0’
(+0)10  (0 000)2
(−0)10  (0 000)2

1’s Comp. 1111


+ 1
1 0000

36 /
45
2’s Complement Range
 4-Bit Representation Decimal 2’s Comp.
4 +7 0111
2 = 16 Combinations
+6 0110
− 8 ≤ Number ≤ + 7 +5 0101
3 3
−2 ≤ Number ≤ + 2 − 1 +4 0100
 n-Bit Representation +3 0011
n−1 n−1 +2 0010
−2 ≤ Number ≤ + 2 − 1 +1 0001
+0 0000
−1 1111
−2 1110
−3 1101
−4 1100
−5 1011
−6 1010
−7 1001
−8 1000
37 /
45
Number Representations
 4-Bit Example

Unsigned Signed
1’s Comp. 2’s Comp.
Binary Magnitude

Range 0 ≤ N ≤ 15 -7 ≤ N ≤ +7 -7 ≤ N ≤ +7 -8 ≤ N ≤ +7

0 0 0
Positive
Binary Binary Binary Binary

1 1 1
Negative X
Binary 1’s Comp. 2’s Comp.
38 /
45
Binary Subtraction Using 1’s Comp. Addition
 Change “Subtraction” to “Addition”
 If “Carry” = 1
then add it to the (5)10 – (1)10 (5)10 – (6)10
LSB, and the result
is positive (+5)10 + (-1)10 (+5)10 + (-6)10
(in Binary)
 If “Carry” = 0 0101 0101
then the result + 1110 + 1001
is negative
(in 1’s Comp.) 1 0011 0 1110
+

0100 1110

+4 −1 39 /
45
Binary Subtraction Using 2’s Comp. Addition
 Change “Subtraction” to “Addition”
 If “Carry” = 1
ignore it, and the (5)10 – (1)10 (5)10 – (6)10
result is positive
(in Binary) (+5)10 + (-1)10 (+5)10 + (-6)10
 If “Carry” = 0
then the result 0101 0101
is negative + 1111 + 1010
(in 2’s Comp.)
1 0100 0 1111

+4 −1

40 /
45
Binary Numbers and Binary Coding

 Flexibility of representation
 Within constraints below, can assign any binary
combination (called a code word) to any data as long as
data is uniquely encoded.
 Information Types
 Numeric
 Must represent range of data needed
 Very desirable to represent data such that simple, straightforward
computation for common arithmetic operations permitted
 Tight relation to binary numbers

 Non-numeric
 Greater flexibility since arithmetic operations not applied.
 Not tied to binary numbers

Chapter 1 41
Non-numeric Binary Codes

 Given n binary digits (called bits), a binary code is a


mapping from a set of represented elements to a
subset of the 2n binary numbers.
 Example: A Color Binary Number
binary code Red 000
for the seven Orange 001
Yellow 010
colors of the
Green 011
rainbow Blue 101
 Code 100 is Indigo 110
Violet 111
not used

Chapter 1 42
Number of Elements Represented

 Given n digits in radix r, there are rn distinct elements that can be


represented.
 But, you can represent m elements, m < rn
 Examples:
 You can represent 4 elements in radix r = 2 with n = 2 digits: (00, 01,
10, 11).
 You can represent 4 elements in radix r = 2 with n = 4 digits: (0001,
0010, 0100, 1000).
 This second code is called a "one hot" code.

Chapter 1 43
DECIMAL CODES - Binary Codes for Decimal Digits
There are over 8,000 ways that you can chose 10
elements from the 16 binary numbers of 4 bits. A few
are useful:
Decimal 8,4,2,1 Excess3 8,4,-2,-1 Gray
0 0000 0011 0000 0000
1 0001 0100 0111 0100
2 0010 0101 0110 0101
3 0011 0110 0101 0111
4 0100 0111 0100 0110
5 0101 1000 1011 0010
6 0110 1001 1010 0011
7 0111 1010 1001 0001
8 1000 1011 1000 1001
9 1001 1 100 1111 1000

Chapter 1 44
Binary Coded Decimal (BCD)

 The BCD code is the 8,4,2,1 code.


 8, 4, 2, and 1 are weights
 BCD is a weighted code
 This code is the simplest, most intuitive binary code
for decimal digits and uses the same powers of 2 as
a binary number, but only encodes the first ten
values from 0 to 9.
 Example: 1001 (9) = 1000 (8) + 0001 (1)
 How many “invalid” code words are there?
 What are the “invalid” code words?

Chapter 1 45
Excess 3 Code and 8, 4, –2, –1 Code

Decimal Excess 3 8, 4, –2, –1


0 0011 0000
1 0100 0111
2 0101 0110
3 0110 0101
4 0111 0100
5 1000 1011
6 1001 1010
7 1010 1001
8 1011 1000
9 1100 1111
 What interesting property is common to these two codes?

Chapter 1 46
Warning: Conversion or Coding?
 Do NOT mix up conversion of a decimal number to a binary
number with coding a decimal number with a BINARY CODE.

1310 = 11012 (This is conversion)


13  0001|0011 (This is coding)

Chapter 1 47
ALPHANUMERIC CODES - ASCII Character Codes

 American Standard Code for Information


Interchange (Refer to Table 1-4 in the text)
 This code is a popular code used to represent
information sent as character-based data. It uses 7-
bits to represent:
 94 Graphic printing characters.
 34 Non-printing characters
 Some non-printing characters are used for text
format (e.g. BS = Backspace, CR = carriage return)
 Other non-printing characters are used for record
marking and flow control (e.g. STX and ETX start and
end text areas).
Chapter 1 48
ASCII Table

49
ASCII Properties
ASCII has some interesting properties:
Digits 0 to 9 span Hexadecimal values 3016 to 3916.
Upper case A-Z span 4116 to 5A16 .
Lower case a -z span 6116to 7A16.
• Lower to upper case translation (and vice versa)
occurs byflipping bit 6.
Delete (DEL) is all bits set,a carryover from when
punched paper tape was used to store messages.
Punching all holes in a row erased a mistake!

Chapter 1 50
PARITY BIT Error-Detection Codes

 Redundancy (e.g. extra information), in the form of


extra bits, can be incorporated into binary code
words to detect and correct errors.
 A simple form of redundancy is parity, an extra bit
appended onto the code word to make the number
of 1’s odd or even. Parity can detect all single-bit
errors and some multiple-bit errors.
 A code word has even parity if the number of 1’s in
the code word is even.
 A code word has odd parity if the number of 1’s in
the code word is odd.

Chapter 1 51
Error Detecting Codes
 Parity
One bit added to a group of bits to make the total number of
‘1’s (including the parity bit) even or odd

4-bit Example 7-bit Example


 Even

 Odd 1 0 1 1 1 0 1 0 0 0 0 0 1
 Good for checking single-bit errors
0 0 1 1 1 1 1 0 0 0 0 0 1

52 /
45
Gray Code
 One bit changes from Decimal Gray Binary
one code to the next 00 0000 0000
code 01 0001 0001
02 0011 0010
 Different than Binary 03 0010 0011
04 0110 0100
05 0111 0101
06 0101 0110
07 0100 0111
08 1100 1000
09 1101 1001
10 1111 1010
11 1110 1011
12 1010 1100
13 1011 1101
14 1001 1110
15 1000 1111

53 / 45

You might also like