Download Data Representation and Gates

Document related concepts

Flexible electronics wikipedia , lookup

Dynamic range compression wikipedia , lookup

Rectiverter wikipedia , lookup

Analog-to-digital converter wikipedia , lookup

Flip-flop (electronics) wikipedia , lookup

Integrated circuit wikipedia , lookup

Digital electronics wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
Data Representation and
Gates
These slides are taken from your
textbook Dale & Lewis
Data and Computers
Computers store, present, and help us
modify
•
•
•
•
•
2
Numbers
Text
Audio
Images and graphics
Video
Data and Computers
Data compression
Reduction in the amount of space needed to store
a piece of data
Compression ratio
The size of the compressed data divided by the
size of the original data
A data compression techniques can be
lossless, which means the data can be retrieved
without any loss of the original information
lossy, which means some information may be lost in
the process of compaction
3
Analog and Digital Information
Information can be represented in one of two
ways: analog or digital
Analog data
A continuous representation, analogous to the actual
information it represents
Digital data
A discrete representation, breaking the information up
into separate elements
Analog and Digital Information
4
Analog and Digital Information
Computers cannot work well with analog data, so
we digitize the data
Digitize
Breaking data into pieces and representing those
pieces separately
5
Electronic Signals
Important facts about electronic signals
• An analog signal continually fluctuates in
voltage up and down
• A digital signal has only a high or low state,
corresponding to the two binary digits
6
Electronic Signals (Cont’d)
Figure 3.2
An analog and a digital signal
7
Figure 3.3
Degradation of analog and digital signals
Binary Representations
Counting with
binary bits
Figure 3.4
8
Representing Negative Values
Signed-magnitude number
representation
The sign represents the ordering, and the
digits represent the magnitude of the
number
9
Signed binary
• signed-magnitude
• The most significant bit (MSB) is set aside to
indicate the sign, zero for positive and 1 for
negative.
• One’s-complement
• The MSB of a negative number will begin with a
one and a positive number with a zero. 0011
will represent +3 and 1100 (complement of the
positive 3) will represent -3.
• Two’s-complement.
• a negative number is represented by
complementing the bits of the positive number
and adding a 1. a –3 is represented as 1101
(complement of 0011 is 1100, and add a 1).
Two’s complement
• a binary number’s MSB is a zero then it
is a positive and no further action is
necessary.
• If the MSB is 1, it is a negative number.
• Suppose the number is 10000001, we
know it is a negative number.
Complement the bits and add a 1, we
get 01111110 +1 = 01111111 which is
127.
• The sign is already determined to be
negative it is –127.
Number Overflow
What happen if the computed value won't fit?
Overflow
If each value is stored using eight bits, adding 127
to 3 overflows
1111111
+ 0000011
10000010
Problems occur when mapping an infinite world
onto a finite machine!
12
Representing Text
What must be provided to represent text?
There are finite number of characters to represent,
so list them all and assign each a binary string
Character set
A list of characters and the codes used to
represent each one
Computer manufacturers agreed to standardize
13
The ASCII Character Set
ASCII stands for American Standard Code
for Information Interchange
ASCII originally used seven bits to
represent each character, allowing for 128
unique characters
Later extended ASCII evolved so that all
eight bits were used
How many characters could be
represented?
14
ASCII Character Set Mapping
15
The ASCII Character Set
The first 32 characters in the ASCII
character chart do not have a simple
character representation to print to the
screen
What do you think they are used for?
16
The Unicode Character Set
Extended ASCII is not enough for
international use
One Unicode mapping uses 16 bits per
character
How many characters can this mapping
represent?
Unicode is a superset of ASCII
The first 256 characters correspond exactly
to the extended ASCII character set
17
The Unicode Character Set
18
Figure 3.6 A few characters in the Unicode character set
Text Compression
Assigning 16 bits to each character in a
document uses too much file space
We need ways to store and transmit text
efficiently
Text compression techniques
keyword encoding
run-length encoding
Huffman encoding
19
Keyword Encoding
Replace frequently used words with a single
character
20
Keyword Encoding
Given the following paragraph,
We hold these truths to be self-evident, that all men
are created equal, that they are endowed by their
Creator with certain unalienable Rights, that among
these are Life, Liberty and the pursuit of Happiness. ム
That to secure these rights, Governments are
instituted among Men, deriving their just powers from
the consent of the governed, ム That whenever any
Form of Government becomes destructive of these
ends, it is the Right of the People to alter or to abolish
it, and to institute new Government, laying its
foundation on such principles and organizing its
powers in such form, as to them shall seem most
likely to effect their Safety and Happiness.
21
Keyword Encoding
The encoded paragraph is
We hold # truths to be self-evident, $ all men are
created equal, $ ~y are endowed by ~ir Creator with
certain unalienable Rights, $ among # are Life,
Liberty + ~ pursuit of Happiness. — $ to secure #
rights, Governments are instituted among Men,
deriving ~ir just powers from ~ consent of ~ governed,
— $ whenever any Form of Government becomes
destructive of # ends, it is ~ Right of ~ People to alter
or to abolish it, + to institute new Government, laying
its foundation on such principles + organizing its
powers in such form, ^ to ~m shall seem most likely to
effect ~ir Safety + Happiness.
22
Keyword Encoding
What did we save?
Original paragraph
656 characters
Encoded paragraph
596 characters
Characters saved
60 characters
Compression ratio
596/656 = 0.9085
Could we use this substitution chart for all text?
23
Run-Length Encoding
A single character may be repeated over
and over again in a long sequence
Replace a repeated sequence with
– a flag character
– repeated character
– number of repetitions
*n8
– * is the flag character
– n is the repeated character
– 8 is the number of times n is repeated
24
Run-Length Encoding
Original text
bbbbbbbbjjjkllqqqqqq+++++
Encoded text
*b8jjjkll*q6*+5 (Why isn't l encoded? J?)
The compression ratio is 15/25 or .6
Encoded text
*x4*p4l*k7
Original text
xxxxpppplkkkkkkk
This type of repetition doesn’t occur in English text; can you think of a
situation where it might occur?
25
Huffman Encoding
Why should the character “X" and "z" take
up the same number of bits as "e" or " "?
Huffman codes use variable-length bit
strings to represent each character
More frequently used letters have shorter
strings to represent them
26
Huffman Encoding
ballboard would be
1010001001001010110001111011
compression ratio
28/56
Encode roadbed
27
Representing Audio Information
We perceive sound when a series of air compressions vibrate a
membrane in our ear, which sends signals to our brain
28
Representing Audio Information
A stereo sends an electrical signal to a speaker to produce
sound
This signal is an analog representation of the sound wave
The voltage in the signal varies in direct proportion to the
sound wave
29
Representing Audio
Information
Digitize the signal by sampling
– periodically measure the voltage
– record the numeric value
How often should we sample?
A sampling rate of about 40,000 times per
second is enough to create a reasonable
sound reproduction
30
Representing Audio
Information
Some data
is lost, but a
reasonable
sound is
reproduced
31
Figure 3.8 Sampling an audio signal
Representing Audio
Information
CDs store audio information digitally
On the surface of the CD are microscopic
pits that represent binary digits
A low intensity laser is pointed as the disc
The laser light reflects
strongly if the surface is smooth and
poorly if the surface is pitted
32
Representing Audio
Information
Figure 3.9
A CD player reading
binary information
33
Audio Formats
Audio Formats
– WAV, AU, AIFF, VQF, and MP3
MP3 (MPEG-2, audio layer 3 file) is dominant
– analyzes the frequency spread and discards
information that can’t be heard by humans
– bit stream is compressed using a form of Huffman
encoding to achieve additional compression
Is this a lossy or lossless compression (or both)?
34
Representing Images and
Graphics
Color
Perception of the frequencies of light that
reach the retinas of our eyes
Retinas have three types of color
photoreceptor cone cells that correspond to
the colors of red, green, and blue
35
Representing Images and
Graphics
Color is expressed as an RGB (red-greenblue) value--three numbers that indicate the
relative contribution of each of these three
primary colors
An RGB value of (255, 255, 0) maximizes
the contribution of red and green, and
minimizes the contribution of blue, which
results in a bright yellow
36
Representing Images and
Graphics
37
Figure 3.10 Three-dimensional color space
Digitized Images and Graphics
Digitizing a picture
Representing it as a collection of individual dots
called pixels
Resolution
The number of pixels used to represent a picture
Raster Graphics
Storage of data on a pixel-by-pixel basis
Bitmap (BMP), GIF, JPEG, and PNG are rastergrahics formats
38
Digitized Images and Graphics
Bitmap format
Contains the pixel color values of the image from left to
right and from top to bottom
GIF format (indexed color)
Each image is made up of only 256 colors
JPEG format
Averages color hues over short distances
PNG format
Like GIF but achieves greater compression with wider
range of color depths
Which is better for line drawings? Pictures?
39
Digitized Images and Graphics
Whole
picture
Figure 3.12 A digitized picture composed of many individual pixels
40
Digitized Images and Graphics
Magnified portion
of the picture
See the pixels?
Figure 3.12 A digitized picture composed of many individual pixels
41
Representing Video
Video codec COmpressor/DECompressor
Methods used to shrink the size of a movie to
allow it to be played on a computer or over a
network
Almost all video codecs use lossy
compressions to minimize the huge amounts
of data associated with video
42
Representing Video
Temporal compression
A technique based on differences between
consecutive frames: If most of an image in two
frames hasn’t changed, why should we waste
space to duplicate all of the similar information?
Spatial compression
A technique based on removing redundant
information within a frame: This problem is
essentially the same as that faced when
compressing still images
43
Computers and Electricity
Gate
A device that performs a basic operation on
electrical signals
Circuits
Gates combined to perform more
complicated tasks
Computers and Electricity
How do we describe the behavior of gates and
circuits?
Boolean expressions
Uses Boolean algebra, a mathematical notation for
expressing two-valued logic
Logic diagrams
A graphical representation of a circuit; each gate has its
own symbol
Truth tables
A table showing all possible input value and the associated
output values
Gates
Six types of gates
–
–
–
–
–
–
NOT
AND
OR
XOR
NAND
NOR
Typically, logic diagrams are black and white with
gates distinguished only by their shape
We use color for emphasis (and fun)
NOT Gate
A NOT gate accepts one input signal (0 or 1) and
returns the opposite signal as output
Figure 4.1 Various representations of a NOT gate
AND Gate
An AND gate accepts two input signals
If both are 1, the output is 1; otherwise,
the output is 0
Figure 4.2 Various representations of an AND gate
OR Gate
An OR gate accepts two input signals
If both are 0, the output is 0; otherwise,
the output is 1
Figure 4.3 Various representations of a OR gate
XOR Gate
An XOR gate accepts two input signals
If both are the same, the output is 0; otherwise,
the output is 1
Figure 4.4 Various representations of an XOR gate
XOR Gate
Note the difference between the XOR gate
and the OR gate; they differ only in one
input situation
When both input signals are 1, the OR gate
produces a 1 and the XOR produces a 0
XOR is called the exclusive OR
NAND Gate
The NAND gate accepts two input signals
If both are 1, the output is 0; otherwise,
the output is 1
Figure 4.5 Various representations of a NAND gate
NOR Gate
The NOR gate accepts two input signals
If both are 0, the output is 1; otherwise,
the output is 0
Figure 4.6 Various representations of a NOR gate
Review of Gate Processing
A NOT gate inverts its single input
An AND gate produces 1 if both input values are 1
An OR gate produces 0 if both input values are 0
An XOR gate produces 0 if input values are the
same
A NAND gate produces 0 if both inputs are 1
A NOR gate produces a 1 if both inputs are 0
Gates with More Inputs
Gates can be designed to accept three or more input
values
A three-input AND gate, for example, produces an output of
1 only if all input values are 1
Figure 4.7 Various representations of a three-input AND gate
Constructing Gates
Transistor
A device that acts either as a wire that conducts
electricity or as a resistor that blocks the flow of
electricity, depending on the voltage level of an
input signal
A transistor has no moving parts, yet acts like
a switch
It is made of a semiconductor material, which is
neither a particularly good conductor of
electricity nor a particularly good insulator
Constructing Gates
A transistor has three terminals
– A source
– A base
– An emitter, typically
connected to a ground wire
If the electrical signal is
grounded, it is allowed to
flow through an alternative
route to the ground (literally)
where it can do no harm
Figure 4.8 The connections of a transistor
Constructing Gates
The easiest gates to create are the NOT, NAND,
and NOR gates
Figure 4.9 Constructing gates using transistors
Circuits
Combinational circuit
The input values explicitly determine the output
Sequential circuit
The output is a function of the input values and the
existing state of the circuit
We describe the circuit operations using
Boolean expressions
Logic diagrams
Truth tables
Are you surprised?
Combinational Circuits
Gates are combined into circuits by using the
output of one gate as the input for another
Combinational Circuits
Three inputs require eight rows to describe all possible
input combinations
This same circuit using a Boolean expression is (AB + AC)
Combinational Circuits
Consider the following Boolean expression A(B + C)
Does this truth table look familiar?
Compare it with previous table
Combinational Circuits
Circuit equivalence
Two circuits that produce the same output for
identical input
Boolean algebra allows us to apply provable
mathematical principles to help design circuits
A(B + C) = AB + BC (distributive law) so circuits
must be equivalent
Properties of Boolean Algebra
Adders
At the digital logic level, addition is
performed in binary
Addition operations are carried out
by special circuits called, appropriately,
adders
Adders
The result of adding two
binary digits could
produce a carry value
Recall that 1 + 1 = 10
in base two
Half adder
A circuit that computes
the sum of two bits
and produces the
correct carry bit
Truth table
Half Adder
#include <iostream.h>
void main()
{
short x,y, sum, carry;
bool a,b,c,d;
cout <<"Enter two bits to add seperated by a space ";cin >>
x>>y;
a=x==1; b=y==1; //actually c++ assigns 0 for false and 1 for
true, we could have read these directly;
c=(a||b) && !(a&&b);
d=(a&&b);
9
sum=c?1:0; //if c is true then sum gets 1 else sum gets 0
carry=d?1:0;
cout <<x <<"+"<<y <<"="<<carry<<sum<<endl;
if (a = true) cout <<"it is true";
if (a) cout << "it is ture";
}
Adders
Circuit diagram
representing
a half adder
Boolean expressions
sum = A  B
carry = AB
Adders
Full adder
A circuit that takes the carry-in value into account
Figure 4.10 A full adder
Multiplexers
Multiplexer
A circuit that uses a few input control signals
to determine which of several output data
lines is routed to its output
Multiplexers
Figure 4.11 A block diagram of a multiplexer with three
select control lines
The control lines
S0, S1, and
S2
determine
which of eight
other input
lines
(D0 … D7)
are routed to the
output (F)
Circuits as Memory
Digital circuits can be used to store
information
These circuits form a sequential circuit,
because the output of the circuit is also
used as input to the circuit
Circuits as Memory
An S-R latch stores a
single binary digit
(1 or 0)
There are several
ways an S-R latch
circuit can be
designed using
various kinds of
gates
Figure 4.12 An S-R latch
Circuits as Memory
The design of this circuit
guarantees that the two
outputs X and Y are always
complements of each other
The value of X at any point in
time is considered to be the
current state of the circuit
Therefore, if X is 1, the circuit is
storing a 1; if X is 0, the circuit
is storing a 0
Figure 4.12 An S-R latch
Integrated Circuits
Integrated circuit (also called a chip)
A piece of silicon on which multiple gates
have been embedded
Silicon pieces are mounted on a plastic or
ceramic package with pins along the
edges that can be soldered onto circuit
boards or inserted into appropriate sockets
Integrated Circuits
Integrated circuits (IC) are classified by the
number of gates contained in them
Integrated Circuits
Figure 4.13 An SSI chip contains independent NAND gates
CPU Chips
The most important integrated circuit
in any computer is the Central Processing
Unit, or CPU
Each CPU chip has a large number of pins
through which essentially all
communication in a computer system
occurs
Computer Programming
Languages
• Computers perform operations such as moving data and data
manipulation by activating switches and gates.
• Instructions to do that also must be given in the form of 1s and 0s or
on and off.
• When we program computers using just ones and zeros we are
using the “machine language”.
• When a program is written using human readable code line for line
of machine code, that language is called Assembly language.
Human readable code is called Mnemonics.
• When a programmer can use mathematical symbols and familiar
English words such as write (a+b) that language is called a High
Level language. Each of the program line will be converted to
several lines of assembly or machine code.
• More about it later
University of Texas Pan
Am
Dr. John P. Abraham