Title: Computer Engineering
1Computer Engineering
- By
- Dr. M. Moustafa Hassan
- Elec. Power Engineering
- Cairo University, Giza, Egypt
2Computer Engineering
- Topics
- Binary Representation
- Reliability thereof
- Binary Storage Devices
- Learning Objectives
- Understand why binary is used, to translate
between decimal and binary and to do simple
binary calculations - Know the conditions of a bistable environment and
the way light switches, magnetic cores and
transistors meet them.
3Data Representation
- Notational conventions for representing
information - Decimal representation for numerical values
- 0,1,2,3,4,5,6,7,8,9
- Signed notation ,- (unsigned means positive
only) - Decimal Notation for real numbers
- Decimal point separates whole number part from
fractional part - The 26 letters A,B,C,X,Y,Z for text
- Plus lowercase and punctuation
- Digitizing Sound and Images
4Data Representation
5Decimal Representation
- In decimal, the following symbols are used to
represent different values 0, 1, 2, 3, 4, 5, 6,
7, 8, 9. - Heres four thousand, seven hundred and
sixty-three in decimal. - 1000s 100s 10s 1s 103 102
101 100 4 7 6 3 - or, it can be written this way
- (4 x 1000) (7 x 100) (6 x 10) (3 x 1)
4763
6Binary Representation
- In the binary system, just two symbols are used
0 and 1. - Therefore any number must be represented by 0s
and 1s only - Lets examine a 6 digit (bit) binary number
- 1 1 1 0 0 1
- Position value 25 24 23 22 21 20
- 32 16 8 0 0 1
- 57
- This kind of a table makes conversions easy
7- Binary-to-Decimal
- Conversion Table
8Converting Decimal Numbers to Binary
- 53 32 16 4 1
- 25 24 22 20
- 125 124 023 122 021 120
- 110101 in binary
- 00110101 as a full byte in binary
- 211 128 64 16 2 1
- 27 26 24 21 20
- 127 126 025 124 023 022
- 121 120
- 11010011 in binary
9Converting Decimal Numbers to Binary
- What is 10011010 in decimal?
- 10011010 127 026 025 124 123
- 022 121 020
- 27 24 23 21
- 128 16 8 2
- 154
- What is 00101001 in decimal?
- 00101001 027 026 125 024 123
- 022 021 120
- 25 23 20
- 32 8 1
- 41
10Max. Integer
- Every computer has a maximum number of bits used
to store an integer - Given k bits, the largest unsigned integer is 2k
- 1 - 16 bit 216 1 65,535
- 32 bit 232 1 4,294,967,296
- Adding just one more (than max) causes an
arithmetic overflow error.
11Neg. Integer Sign/Magnitude
- We desire the availability of negative integers
- Let the most significant bit will represent
negation negative if on, positive if off - Our previous 6 digit binary now needs an extra
bit to make it negative - Here it is in full 1 byte representation
- Can you see a problem with this scheme?
1 0 1 1 1 0 0 1 Position value neg. 26 25 24
23 22 21 20 - 0 32 16 8 0 0
1 - 57
12Neg. Integer Twos Complement
- The most common way of storing integers
- The most significant bit will represent negative
128 (-128) - Heres 57 and -57 in full 1 byte representation
- Whats the range of a 1 byte integer ?
1 1 0 0 0 1 1 1 Position value -27 26 25 24 2
3 22 21 20 -128 64 0 0 0
4 2 1 -
57 0 0 1 1 1 0 0 1 Position
value -27 26 25 24 23 22 21 20 -0 0
32 16 8 0 0 1
57
13Representing Real Numbers
- Real numbers may be put into binary scientific
notation for storage a x 2b - First, convert from decimal to binary
- Example
- 5.75 is 101.11 in binary
- 5 is 101 and
- .75 is .11
-
- in decimal there are 10ths, 100ths, 1000ths, etc
while in binary - there are halves, quarters, eighths, etc
- So .75 is made up of a half and a qtr written .11
14Real Numbers
Step 3) Normalize 5.75 101.11 x 20 5.75
10.111 x 21 5.75 1.0111 x 22 5.75 .10111 x
23 Which is (1/2 1/8 1/16 1/32) x 8 5.75
- Second, use scientific binary notation
- 101.11 is 101.11 x 20
- Third, normalize so that first significant digit
is immediately to the right of the binary point
(see next for further explanation) - .10111 x 23
- Fourth, store mantissa and exponent
0 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1
Mantissa
Exponent
Sign of Mantissa
Sign of Exponent
Binary Point
15Negative Real Numbers
- First, convert to binary
- -5/16 is -(1/4 1/16) is -0.0101
- Second, use scientific binary notation
- -0.0101 x 20
- Third, normalize
- -.101 x 2-1
- Fourth, stored mantissa and exponent
1 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1
Mantissa
Exponent
Sign of Mantissa
Sign of Exponent
Binary Point
16Lets Practice
- Convert the following to binary using the
standard notation - 78, 255
- Convert the following to binary using twos
complement notation - -78, -105, 118
- Convert several bit patterns to decimal
- HINT use windows calc to check your answers
- Convert -3.0625 to binary
17Binary Representation of Characters
- Each character is represented by a unique
(binary) number - The ASCII table is the most common scheme
- Uses 8 bits 28 or 256 different characters
- First 7 bits only (actually 8-bit ASCII is a
misnomer) - Unicode
- Uses 16 bits 216 or 65,536 different characters
- Go to http//www.cs.tut.fi/jkorpela/chars.html
for an excellent tutorial on character code
issues - IMPORTANT NOTE the numeric value of number
characters is NOT the same as the usual
arithmetic value. - ie The character 7 has the numeric value 55
18Examples of ASCII Codes
19(No Transcript)
20IMPORTANT NOTE
- The computer does not know what a specific bit
pattern in memory means - The meaning is imposed only as a result of how
some process has been designed to interpret the
pattern - Strong Typing In writing programs we declare
how we will use locations in memory (java c) - boolean b means 1 bit that can be true or false
- byte number means a signed 8 bit integer
- int number means a signed 32 bit integer
- char ch means a 16 bit uni-code character
(note we only discuss the 7 bit portion used in
the lower ASCII char set) - Loose Typing Some programming (scripting)
languages are able to do this automatically (php,
perl) - Which is better? it depends! Read More !!.
21Binary Representation of Sound
- Multimedia data is sampled to store in digital
form, with or without detectable differences - Representing sound data
- Sound data must be digitized for storage in a
computer - Digitizing means periodic sampling of amplitude
values
22Sound (continued)
- From samples, original sound may be approximated
- To improve the approximation
- Sample more frequently
- Use more bits for each sample value
23- Figure 4.5
- Digitization of an Analog Signal
- (a) Sampling the Original
- Signal
- (b) Recreating the
- Signal from the Sampled
- Values
24Representing Image Data
- Images are sampled by reading color and intensity
values at even intervals (a grid) across the image
25Representing Image Data
- The size of the grid is called resolution
- 1024 x 768 or 1600 x 1200
- Each sampled point is a pixel
- Image quality depends on number of bits at each
pixel - True-Color (24bit) uses 1 byte for each of red,
green blue to represent over 16 million colours
at each pixel - What is the storage requirement (size) of a
True-Color image with a resolution of 1600 x 1200?
26Putting it into Perspective
- Encoding the text (no images) like a text book
- 100,000 words x 5 char/word x 8 bits/char
4,000,000 bits - 1 minute of sound using MP3 (44,100 samples/sec
using a 16 bit depth - 44,100 samples/sec x 16 bits/sample x 60
sec/minute 42,000,000 bits - 1 photo using a 3 mega pixel camera
- 3,000,000 pix/photo x 24 bits/pixel 72,000,000
bits
27Data Compression
- Compression Ratio
- Ratio Size of Uncompressed / Size of Compressed
- Lossless
- No data is lost during compression
- Used when compressing text
- 1.5 to 1.7 compression ratios
- Lossy
- The higher the compression the higher the loss
- Used for sound and images
- 10, 20 higher compression ratios
28Reliability
- Q Why binary ?
- A Electrical systems work best in a bistable
environment. - That is, an electrical component can remain
accurate as it ages (and drifts). - If it only needs to deal with voltage or no
voltage circuit on/circuit off - The text points out that nearly a 50 drift in
voltage is still tolerable when interpreting a
stored value.
29Binary Storage Devices
- Binary Hardware Criteria
- 2 stable energy states
- A large energy barrier between them
- Ability to read the state without destroying it
- Ability to change the state as needed
- Two approaches
- Magnetic Cores historic
- Transistors current
30Magnetic Cores
- An Iron oxide-coated donut can be magnetized by
running current through a wire strung through its
whole - The direction of the resulting magnetic field is
dependant upon the direction of the current - right-hand rule
Even though these mag cores where small (1/50
dia) it would take a cube 230 per side to
construct a modern 512 mb memory !!!
31Magnetic Cores to Represent Binary Values
32Transistor
- Just a switch its turned on/off electrically
- Current technology (at text book printing)
- Switch state 1 billionth of a sec
- Density 30 to 50 million per cm2
- Made from semiconductors (silicon or gallium
arsenide) - Transistors are printed photographically onto a
wafer of silicon using a mask. - This is used to produce many copies of the
circuit (chip).
33Relationship of Transistors, Chips
34Transistor Model
35Interesting Links
- Binary Numbers
- http//www.math.grin.edu/rebelsky/Courses/152/97F
/Readings/student-binary.html - Character Issues
- http//www.cs.tut.fi/jkorpela/chars.html
- Core Memory
- http//www.psych.usyd.edu.au/pdp-11/core.html
- Transistor
- http//www.pbs.org/transistor/
- Semiconductor
- http//www.answers.com/topic/semiconductor
36George Boole (1815 1864)
- Created a new form of logic containing the values
true and false and the operators AND OR NOT - Developed a set of rules to interpret and
manipulate expressions that contain these values - 100 years later his theories became the framework
for designing computer systems
37Boolean Logic
- Boolean Logic deals with manipulating the values
true and false - Anything stored in a sequence of binary digits
can also be viewed as a sequence of logical
values, true and false - The operators AND, OR, NOT map a set of True
False values into a single (true/false) result
38Boolean Logic
- Any expression can be either true or false
- IE x y 25
- A boolean expression combines arithmetic
expressions using the boolean operators - AND (x y 25 AND y lt 100)
- OR (x y OR x lt 10)
- NOT (NOT (x y))
39AND rule
- a AND b, also written as a?b, is true only if the
value of a and the value of b is true - Otherwise the expression a?b has the value of
false - To check a test score S in the range 90 to 100
inclusive - Sgt90 AND Slt100
40Truth Table for AND Operation
Input Input Output
a b a AND b
FALSE FALSE FALSE
FALSE TRUE FALSE
TRUE FALSE FALSE
TRUE TRUE TRUE
41OR rule
- a OR b, also written as ab, is true if the value
of a is true, if value of b is true, or both are
true - Otherwise the expression ab has the value of
false - To check a students major
- (major math) OR (major comp science)
42Truth Table for OR Operation
Input Input Output
a b a OR b
FALSE FALSE FALSE
FALSE TRUE TRUE
TRUE FALSE TRUE
TRUE TRUE TRUE
43NOT rule
- NOT reverses or complements the value of the
Boolean expression - Not a, also written as a, is true if a has the
value of false and false if a has the value of
true - To compare a students gpa
- (gpa gt 3,5) is true if your gpa is greater than
3.5 - NOT (gpa gt 3.5) is true only if your gpa 3.5
44Truth Table for NOT Operation
Input Output
a NOT a
FALSE TRUE
TRUE FALSE
45Precedence
- The order of precedence rule for boolean
operations is NOT first, AND second and OR third. - So
- x AND NOT y OR z
- Means
- (x AND (NOT y)) OR z
- Parentheses can be used to change the order and
are recommended where needed to enhance
readability
46Other Boolean Logic Symbols
English Math Java
TRUE 1 true
FALSE 0 false
NOT ? !
(Negation NOT false is true and NOT
true is false)
AND ?
(Conjunction P AND Q is true only when both P
Q are true)
OR ?
(Disjunction P OR Q is true when P is true,
or Q is true, or both)
47Truth Table 1
- Shows the truth or falsity of a logical
expression for every possible logical value
assignment.
P (Q R)
0 0 0 1 0 0 0 1
0 0 0 1 1 1 1 1
48Truth Table 2
P !(Q R)
0 0 0 0 1 0 0 0
0 1 1 1 0 1 1 1
1 0 0 0 1 0 0 0
49Review of Boolean Algebra
- Just like Boolean logic
- Variables can only be 1 or 0
- Instead of true / false
50Review of Boolean Algebra
- Not is a horizontal bar above the number
- 0 1
- 1 0
- Or is a plus
- 00 0
- 01 1
- 10 1
- 11 1
- And is multiplication
- 00 0
- 01 0
- 10 0
- 11 1
_
_
51Review of Boolean Algebra
_ _ _
- Example translate (xyz)(xyz) to a Boolean
logic expression - (x?y?z)?(?x??y??z)
- We can define a Boolean function
- F(x,y) (x?y)?(?x??y)
- And then write a truth table for it
x y F(x,y)
1 1 0
1 0 0
0 1 0
0 0 0
52Basic Logic Gates
53Question 1
- Find the output of the following circuit
- Answer (xy)y Or (x?y)??y
xy
__
54Question 2
- Find the output of the following circuit
- Answer xy Or ?(?x??y) x?y
55Question 3
- Draw the circuits for the following Boolean
algebraic expressions - xy
__
56Question 4
- Draw the circuits for the following Boolean
algebraic expressions - (xy)x
_______
xy
57Writing XOR Using AND/OR/NOT
- p ? q ? (p ? q) ? (p ? q)
- x ? y ? (x y)(xy)
x y x?y
1 1 0
1 0 1
0 1 1
0 0 0
____
xy
(xy)(xy)
xy
xy
58Gates AND, OR, NOT
A gate operates on binary inputs to produce
binary outputs
59The NOT Gate
0
1
1
0
60NAND and AND Gates
61NOR and OR Gates
62Important Note
- Gates are another abstraction in Computer Science
- we dont have to deal with transistors,
resistors and capacitors or voltages, current and
resistance the building block of circuit
construction (for us) will be gates and the rules
of Boolean logic!
63Building Computer Circuits
- A combinational circuit (just circuit to us) is
made up of logic gates - That transform a set of binary inputs into a set
of binary outputs, - Where the values of the outputs depend only on
the values of the inputs (no feedback loops) - Sequential circuits (containing feedback loops)
feed the output from a gate back as input to an
earlier gate not discussed here
64Diagram of a Typical Computer Circuit
65Our First Circuit
- c (a OR b)
- d NOT ( (a OR b) AND (NOT b ) )
66Circuit Construction Algorithm
- Construct the truth table
- Every output of 1 denotes a sub-expression
- Create sub-expressions using AND NOT
- each sub-expression becomes a sub-circuit of the
completed circuit - Combine sub-expressions using OR
- sub-circuits are joined with OR gates
- Construct the circuit
- Repeat 2 through 4 for each output column
67The Sum-of-Products Circuit Construction Algorithm
68Truth Table
input input output output
a b o1 o2
0 0 1 0
0 1 0 1
1 0 0 1
1 1 1 0
- What general concept do you think that each
output represents? - Create the sub-expressions
- Combine them
- Construct the circuit
69Circuit Construction
- IMPORTANT The Sum of Products Algorithm
doesnt always produce an optimal circuit - The circuit on the right has the same output as
the one on the left.
70Addition Circuit
- Binary addition
- 11 (the carry bit)
- 001101 (bin value 13)
- 001110 (bin value 14)
- 011011 (bin value 27)
- Relate this to the truth table required for the
circuit (next slide)
71How to Add Binary Numbers
- Consider adding two 1-bit binary numbers x and y
- 00 0
- 01 1
- 10 1
- 11 10
- Carry is x AND y
- Sum is x XOR y
- The circuit to compute this is called a half-adder
x y Carry Sum
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
72The Half-Adder
- Sum x XOR y
- Carry x AND y
73Using Half Adders
- We can then use a half-adder to compute the sum
of two Boolean numbers
0
0
1
1 1 0 0 1 1 1 0
0
1
0
?
74How to Fix This
- We need to create an adder that can take a carry
bit as an additional input - Inputs x, y, carry in
- Outputs sum, carry out
- This is called a full adder
- Will add x and y with a half-adder
- Will add the sum of that to the carry in
- What about the carry out?
- Its 1 if either (or both)
- xy 10
- xy 01 and carry in 1
x y c carry sum
1 1 1 1 1
1 1 0 1 0
1 0 1 1 0
1 0 0 0 1
0 1 1 1 0
0 1 0 0 1
0 0 1 0 1
0 0 0 0 0
75The Full Adder
- The HA boxes are Half-Adders
761-Add Circuit and Truth Table
- Note how the truth table supports binary addition
on the previous slide - Create sub-expressions for Si
- Write the expression for Si
77Sum Output for 1-Add
781-Add
79Building the Full Adder
- Put rightmost bits into 1-ADD, with zero for the
input carry - Send 1-ADDs output value to output, and put its
carry value as input to 1-ADD for next bits to
left - Repeat process for all bits
80The Full Adder Add Circuit
81The Process of Abstraction
- Full Adder as a circuit
- Full Adder using 1-Add
- 1-Add using gates
- Gates using transistors
82The Full Adder
- The full circuitry of the full adder
83Adding Bigger Binary Numbers
- Just chain of full adders together
84Adding Bigger Binary Numbers
- A half adder has 4 logic gates
- A full adder has two half adders plus a OR gate
- Total of 9 logic gates
- To add n bit binary numbers, you need 1 HA and
n-1 FAs - To add 32 bit binary numbers, you need 1 HA and
31 FAs - Total of 4931 283 logic gates
- To add 64 bit binary numbers, you need 1 HA and
63 FAs - Total of 4963 571 logic gates
85More About Logic Gates
- To implement a logic gate in hardware, you use a
transistor. - Transistors are all enclosed in an Integrated
Circuit IC. - The current Intel Pentium IV processors have 55
million transistors!
86Pentium Math Error 1
- Intels Pentiums (60Mhz 100 Mhz) had a
floating point error - Graph of z y/x
- Intel reluctantlyagreed to replace them in 1994
- Graph from http//kuhttp.cc.ukans.edu/cwis/units/I
PPBR/pentium_fdiv/pentgrph.html
87Pentium Math Error 2
- Top 10 reasons to buy a Pentium
- 10 Your old PC is too accurate
- 8.9999163362 Provides a good alibi when the IRS
calls - 7.9999414610 Attracted by Intel's new "You don't
need to know what's inside" campaign - 6.9999831538 It redefines computing--and
mathematics! - 5.9999835137 You've always wondered what it
would be like to be a plaintiff - 4.9999999021 Current paperweight not big enough
- 3.9998245917 Takes concept of "floating point"
to a new level - 2.9991523619 You always round off to the nearest
hundred anyway - 1.9999103517 Got a great deal from the Jet
Propulsion Laboratory - 0.9999999998 It'll probably work!!
88Flip-Flops
- Consider the following circuit
- What does it do?
89Latches And Flip Flops
RS Flip Flop
- What are Flip Flops?
- Flip Flops are digital circuits that have
feedback connections. - Thus, can be used as memory devices, oscillators,
etc.
An AND-OR gate used as a ones catching'' latch
and its timing diagram
90In vivo digital circuits
91Memory
- A flip-flop holds a single bit of memory
- The bit flip-flops between the two NAND gates
- In reality, flip-flops are a bit more complicated
- Have 5 (or so) logic gates (transistors) per
flip-flop - Consider a 1 Gb memory chip
- 1 Gb 8,589,934,592 bits of memory
- Thats about 43 million transistors!
- In reality, those transistors are split into 9
ICs of about 5 million transistors each
92The Digital Advantage!
- In a nut shell Digital signals are more reliable
compared with analog signals! - Positive Negative logic
- We will study - logic and use it in the
design of digital circuits. - Combinational vs. Sequential circuits.
- We will study these two types of circuits and use
them to design complex systems. - Asynchronous vs. Synchronous.
- Sequential circuits can be further classified as
synchronous or asynchronous. - We will study both types.
93Transistors and Physical Size
- How many transistors are needed in a 32-Bit
Adder? - NOT 32 x 3 96 NOT gates _at_ 1 tran/gate
96 - AND 32 x 16 512 AND gates _at_ 3
tran/gate 1536 - OR 32 x 6 192 OR gates _at_ 3
tran/gate 576 - Total 2208
- How big is this addition circuit?
- Built with vacuum tubes
- Built with magnetic cores
- Built with transistors
- NOTE optimized 32-bit addition circuits can be
constructed with FAR fewer transistors (500 600)
94Control Circuits
- Control circuits used to
- determine the order in which operations are
performed - select the correct data values to process
- Definitions (no other meaning matters to us)
- Multiplexor
- From 2N input, select 1 output, using N selector
lines - Decoder
- N input lines determine which ONE of 2N output
lines
95Multiplexor
- N selector lines can select one output from 2N
input lines - Useful to select data
96Multiplexor Example
97Decoder
- N input lines can determine which one (and ONLY
one) of 2N output lines will be turned on - Useful to select the correct instruction
98Decoder Example
99Truth Tables, Expressions Circuits
- You need to be able to create two of these given
the third. Thats any two! - Always use the sum of products algorithm
- Make sure you practice the process enough that
you can FULLY answer an exam question. - What do I mean by fully?
- You may also have to combine circuits to create
more complex circuits.
100Interesting Links
- Binary Numbers
- http//www.math.grin.edu/rebelsky/Courses/152/97F
/Readings/student-binary.html - Character Issues
- http//www.cs.tut.fi/jkorpela/chars.html
- Core Memory
- http//www.psych.usyd.edu.au/pdp-11/core.html
- Transistor
- http//www.pbs.org/transistor/
- Semiconductor
- http//www.answers.com/topic/semiconductor
101Misconceptions And Difficulties
- The distinction between the ASCII representation
of a number as a character and the binary
representation of that number as an integer or
float. - Confusion with construction of gates is common
- Translating the goal of binary addition into the
steps used in creating the adder circuit. - Review the binary addition algorithm
- Function and design of both multiplexors and
decoders is difficult. (roles/quantity of input,
output and selector lines)
102Analysis and Design Tools
- De Morgans Laws
- The duality principle
- Karnaugh maps provide an alternative technique
for representing Boolean functions. - Equivalent circuits (AND-OR and NAND-NAND
circuits)
4-signal Karnaugh map
Karnaugh map representation of a 2-input AND gate
103Karnaugh maps software
http//karnaugh.shuriksoft.com/
Interactive Karnaugh maps http//maui.theoinf.tu-
ilmenau.de/sane/projekte/karnaugh/embed_karnaugh.
html