You are on page 1of 40

KOREA-VIETNAM FRIENDSHIP IT COLLEGE

DIGITAL CIRCUITS

CHAPTER 1:
DIGITAL COMPUTERS
AND INFORMATION

13 October 2006
OVERVIEW

 Digital Computers

 Number Systems

 Arithmetic Operations

 Decimal Codes

 Alphanumeric Codes

October 17, 2008 Chapter 1. Digital Computer and Information 2


DIGITAL COMPUTERS

 Major characteristic
 Manipulation of discrete elements of
information (any set restricted to a finite # of
elements)
 e.g. 10 decimal digits, 26 letters
 Discrete elements (in digital systems) can be
represented by signals (physical quantities).
 Most common signals: electrical (voltage,
current)
October 17, 2008 Chapter 1. Digital Computer and Information 3
Voltage Ranges

The 2 binary values (HIGH, LOW) of a digital signal are


represented by ranges of voltage values
OUTPUT INPUT

HIGH 5.0
HIGH
Output Ranges: 4.0 Input Ranges:
HIGH: 4.0 .. 5.5 V 3.0 HIGH: 3.0 .. 5.5 V
LOW: -0.5 .. 1.0 V 2.0 LOW: -0.5 .. 2.0 V
1.0
LOW LOW
0.0
Volts

Why are the INPUT ranges larger?


 To account for input noise
October 17, 2008 Chapter 1. Digital Computer and Information 4
Information Representation

 Binary signals (2 discrete values)


 0 and 1 (LOW and HIGH, FALSE and
TRUE)
 Binary quantity: binary digit/bit
 Information: group of bits/words (size: 8,
16, 32, 64, …)
 Digital H/W computes binary functions of
binary numbers:
 Combinational (memoryless)
 Sequential (using memory)
October 17, 2008 Chapter 1. Digital Computer and Information 5
Basic Computer Structure

Stores programs,
I/O data, and
intermediate
Memory data

Supervises
Control
the CPU unit
Datapath
flow of info.
among all
units Performs arithmetic
and other data-
Input/Ouput processing
operations
October 17, 2008 Chapter 1. Digital Computer and Information 6
More detailed view

Processor: Internal
Very complex FPU
Cache
Circuit (in the
order of millions CPU
of transistors) MMU

Memory External Cache RAM

October 17, 2008 Chapter 1. Digital Computer and Information 7


NUMBER SYSTEMS

 Representation of numbers
 Radix: “base”, the primitive unit for group of
numbers, e.g. for decimal arithmetic
radix=10 (“base” 10)
 For every system, we need arithmetic
operations (addition, subtraction,
multiplication)
 Also, conversion from one base to another

October 17, 2008 Chapter 1. Digital Computer and Information 8


Number Systems - Decimal

 “base” 10 (radix is 10)


 10 digits: 0..9

 (251.3)10 = 2∗102 + 5∗101 + 1∗100 + 3∗10-1

 Note: ‘.’ is called the radix point (decimal


point for base 10)

October 17, 2008 Chapter 1. Digital Computer and Information 9


Number Systems - Decimal (cont.)

 In general, a decimal number with n digits


to the left of the decimal point, and m digits
to the right of the decimal point is written
as:
An-1 An-2 … A1 A0 . A-1 A-2 … A-m+1 A-m

where Ai is a coefficient between 0..9,


and i denotes the weight (=10i) of Ai.
October 17, 2008 Chapter 1. Digital Computer and Information 10
Number Systems - Decimal (cont.)

The value of

An-1 An-2 … A1 A0 . A-1 A-2 … A-m+1 A-m

is calculated by

∑i=n-1..0 (Ai ∗ 10i ) + ∑i=-m..-1 (Ai ∗ 10i )

October 17, 2008 Chapter 1. Digital Computer and Information 11


Number Systems - General

 “base” r (radix r)
 r digits
 N = An-1 ∗r n-1
+ An-2∗r n-2 +… + A1∗r + A0 +
A-1 ∗r -1 + A-2∗r -2 +… + A-m ∗r -m

Most Least
Significant Significant
Bit (MSB) Bit (LSB)

October 17, 2008 Chapter 1. Digital Computer and Information 12


Number Systems - General (cont.)

 e.g. let r = 8

(215.4)8 = 2∗82 + 1∗81 + 5∗80 + 4∗8-1


= (141.5)10

 Conversion from n-ary (any system with


radix n) to decimal follows similar process
as above

October 17, 2008 Chapter 1. Digital Computer and Information 13


Number Systems (cont.)

 Most common number systems for


computers:
 Binary (r = 2)
 Octal (r = 8)
 Hexadecimal (r = 16)

October 17, 2008 Chapter 1. Digital Computer and Information 14


Binary Numbers - Base 2

 Computers represent all data as “strings of


bits”, each bit being either 0 or 1
 “base” 2, with 2 digits: 0 and 1
 e.g.

(101101.10)2 = 1∗25 + 0∗24 + 1∗23 + 1∗22 + 0∗21


+ 1∗20 + 1∗2-1 + 0∗2-2
(in decimal) = 32 + 0 + 8 + 4 + 0 + 1 + ½ + 0
= (45.5)10
October 17, 2008 Chapter 1. Digital Computer and Information 15
Binary Numbers - Base 2 (cont.)

 e.g.
(1010.101)2 = 1∗23 + 0∗22 + 1∗21 + 0∗20 +
1∗2-1 + 0∗2-2 + 1∗2-3
(in decimal) = 8 + 2 + 0.5 + 0.125
= (10.625)10

October 17, 2008 Chapter 1. Digital Computer and Information 16


Powers of two

n 2n n 2n n 2n
0 1 8 256 16 65,536
1 2 9 512 17 131,072
2 4 10 1,024 18 262,144
3 8 11 2,048 19 524,288
4 16 12 4,096 20 1,048,576
5 32 13 8,192 21 2,097,152
6 64 14 16,384 22 4,194,304
7 128 15 32,768 23 8,388,608
Memorize at least through 216
October 17, 2008 Chapter 1. Digital Computer and Information 17
Octal Numbers - Base 8

 “base” 8, with 8 digits: 0..7


 e.g.

(762)8 = 7∗82 + 6∗81 + 2∗80


(in decimal) = 448 + 48 + 2
= (498)10

October 17, 2008 Chapter 1. Digital Computer and Information 18


Hexadecimal Numbers - Base 16

 r = 16
 Digits (convention): 0..9, A, B, C, D, E, F
 A=10, B=11, … , F = 15
 e.g.

(3FB)16 = 3∗162 + 15∗161 + 11∗160


(in decimal) = 768 + 240 + 11
= (1019)10

October 17, 2008 Chapter 1. Digital Computer and Information 19


Base Conversions

 Any base r → decimal – Easy! (already


covered, see slides 13-14, 16-17, 19-20)
 Decimal → Binary

 Octal ↔ Binary

 Hex ↔ Binary

 Decimal → Any base r

October 17, 2008 Chapter 1. Digital Computer and Information 20


Decimal to Binary

Let N be a decimal number.


 Find the greatest number that is a power of 2 and
when subtracted from N it produces a positive
difference N1
 Put a 1 in the MSB
 Repeat Step 1, starting from N1 and finding
difference N2. Put a 1 in the corresponding bit.
Stop when the difference is zero.

October 17, 2008 Chapter 1. Digital Computer and Information 21


Decimal to Binary (cont.)

e.g. N = (717)10

717 – 512 = 205 = N1 512 = 29


205 –128 = 77 = N2 128 = 27
77 – 64 = 13 = N3 64 = 26
13 – 8 = 5 = N4 8 = 23
5–4 = 1 = N5 4 = 22
1–1 = 0 = N6 1 = 20
 (717)10 = 29 + 2 7 + 26 + 2 3 + 22 + 20
=(1 0 1 1 0 0 1 1 0 1)2
October 17, 2008 Chapter 1. Digital Computer and Information 22
Binary to Octal and Hex

 Octal:
8 = 23  every 3 binary bits convert 1 octal

 Hex:
16 = 24  every 4 binary bits convert 1 hex

October 17, 2008 Chapter 1. Digital Computer and Information 23


Binary ↔ Octal

(010|011|110|000 . 011|101|111|001)2

(2 3 6 0 . 3 5 7 1 )8

October 17, 2008 Chapter 1. Digital Computer and Information 24


Binary ↔ Hex

(1010 0110 1000 . 1100 0101 1111)2

(A 6 8 . C 5 F)16

October 17, 2008 Chapter 1. Digital Computer and Information 25


Octal ↔ Hex

Go through Binary!

Hex  Binary  Octal


Octal  Binary  Hex

October 17, 2008 Chapter 1. Digital Computer and Information 26


Convert Decimal to any base r

 Integer part: Divide by the base, keep track of


remainder, and read-up
 e.g. (153)10 = ( ? )8 , r = 8
153 / 8 = 19 + 1/8 rem = 1 LSB
19 / 8 = 2 + 3/8 rem = 3
2 / 8 = 0 + 2/8 rem = 2 MSB
stop
 (153)10 = ( 231)8

October 17, 2008 Chapter 1. Digital Computer and Information 27


Convert Decimal to any base r

 Fractional part: Multiply by the base, keep


track of integer part, and read-down
 e.g. (0.78125)10 = ( ? )16 , r = 16

0.78125∗ 16 = 12.5 integer = 12 = C MSB


0.5 ∗ 16 = 8.0 integer = 8 = 8 LSB
stop
 (0.78125)10 = (0.C8)16

October 17, 2008 Chapter 1. Digital Computer and Information 28


Binary Arithmetic Operations:
Addition
 Follow same rules as in decimal addition,
with the difference that when sum is 2
indicates a carry (not a 10)
 Learn new carry rules
 0+0 = 0c0 (sum 0 with carry 0)
 0+1 = 1+0 = 1c0
Carry 1 1 1 1 1 0
 1+1 = 0c1
 1+1+1 = 1c1 Augend 0 0 1 0 0 1
Addend 0 1 1 1 1 1
Result 1 0 1 0 0 0
October 17, 2008 Chapter 1. Digital Computer and Information 29
Binary Arithmetic Operations:
Addition (cont.)

 “Half addition” (rightmost bit position, aka


LSB): only 2 bits are added, yielding a sum
and a carry
 “Full addition” (remaining positions): three
bits are added, yielding a sum and a carry
 In Chapter 3, we’ll see many different
hardware implementations of half-adders
and full-adders
October 17, 2008 Chapter 1. Digital Computer and Information 30
Overflow

 If “word size” is fixed to n bits and an


addition results in (n+1) bits, “overflow”
occurs  output number cannot be
correctly represented by the n bits
 Overflow never occurs in subtraction

October 17, 2008 Chapter 1. Digital Computer and Information 31


Binary Arithmetic Operations:
Subtraction
 Learn new borrow rules
 0-0 = 1-1 = 0b0 (result 0 with borrow 0)
 1-0 = 1b0
 0-1 = 1b1 Borrow 1 1 0 0
 …
Minuend 1 1 0 1 1
Subtrahend 0 1 1 0 1
Result 0 1 1 1 0

October 17, 2008 Chapter 1. Digital Computer and Information 32


Keys to Success

 Recall and use the “algorithms” you use to


perform base-10 arithmetic.
 Generalize them to the base in use (carry,
borrow rules change)
 Preserve the base! In binary, 1+1=10

October 17, 2008 Chapter 1. Digital Computer and Information 33


Binary Arithmetic Operations:
Multiplication
 Shift-and-add algorithm, as in base 10

M’cand 0 0 0 1 1 0 1
M’plier 0 0 0 0 1 1 0
(1) 0 0 0 0 0 0 0
(2) 0 0 1 1 0 1 0
(3) 0 1 1 0 1 0 0
Sum 1 0 0 1 1 1 0

 Check: 13 * 6 = 78

October 17, 2008 Chapter 1. Digital Computer and Information 34


CODES

 Representations of info (set) obtained by


associating one or more codewords (a binary
pattern/string) with each element in the set
 n-bit binary code: a group of n bits that can
n
encode up to 2 distinct elements
e.g. A set of 4 distinct numbers can be
represented by 2-bit codes s.t. each number in
the set is assigned exactly one of the
combinations/codes in {00,01,10,11}
October 17, 2008 Chapter 1. Digital Computer and Information 35
CODES (cont.)

 To encode m distinct elements with an n-bit


n
code: 2 >= m
 Note: The codeword associated with each
number is obtained by coding the number,
not converting the number to binary.
 We will see: BCD, ASCII, Unicode

October 17, 2008 Chapter 1. Digital Computer and Information 36


Binary-Coded Decimal (BCD)

 A decimal code: Declmal BCD


Symbol Digit
Decimal numbers (0..9)
0 0000
are coded using 4-bit 1 0001
distinct binary words 2 0010
3 0011
 Observe that the codes
4 0100
1010 .. 1111 (decimal 5 0101
10..15) are NOT 6 0110
7 0111
represented (invalid
8 1000
BCD codes) 9 1001
October 17, 2008 Chapter 1. Digital Computer and Information 37
Binary-Coded Decimal (cont.)

 To code a number with n decimal digits, we


need 4n bits in BCD
e.g. (365)10 = (0011 0110 0101)BCD

 This is different to converting to binary, which


is (365)10 = (101101101)2

 Clearly, BCD requires more bits. BUT, it is


easier to understand/interpret
October 17, 2008 Chapter 1. Digital Computer and Information 38
BCD Addition

 When 2 BCD codes are added:


 If the binary sum is less than 1010 (9 in
decimal), the corresponding BCD sum digit is
correct
 If the binary sum is equal or more than 1010,
must add 0110 (6 in decimal) to the
corresponding BCD sum digit in order to
produce the correct carry into the digit to the
left

October 17, 2008 Chapter 1. Digital Computer and Information 39


BCD Addition (cont.)

 Example: Add 448 and 489 in BCD.

0100 0100 1000 (448 in BCD)


0100 1000 1001 (489 in BCD)
10001 (greater than 9, add 6)
10111 (carry 1 into middle digit)
1101 (greater than 9, add 6)
1001 1 0111 (carry 1 into leftmost digit)
1001 0011 0111 (BCD coding of 93710)

October 17, 2008 Chapter 1. Digital Computer and Information 40

You might also like