Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

79
Data Representation and Gates These slides are taken from your textbook Dale & Lewis

Transcript of Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Page 1: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Data Representation and Gates

These slides are taken from your textbook Dale & Lewis

Page 2: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

2

Data and Computers

Computers store, present, and help us modify

• Numbers• Text• Audio• Images and graphics• Video

Page 3: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

3

Data and Computers

Data compression Reduction in the amount of space needed to store a piece of dataCompression ratio The size of the compressed data divided by the size of the original dataA 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

Page 4: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

4

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

Page 5: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

5

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

Page 6: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

6

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

Page 7: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

7

Electronic Signals (Cont’d)

Figure 3.2 An analog and a digital signal

Figure 3.3 Degradation of analog and digital signals

Page 8: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

8

Binary RepresentationsCounting withbinary bits

Figure 3.4

Page 9: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

9

Representing Negative Values

Signed-magnitude number representation

The sign represents the ordering, and the digits represent the magnitude of the number

Page 10: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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).

Page 11: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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.

Page 12: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

12

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!

Page 13: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

13

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

Page 14: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

14

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?

Page 15: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

15

ASCII Character Set Mapping

Page 16: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

16

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?

Page 17: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

17

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

Page 18: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

18

The Unicode Character Set

Figure 3.6 A few characters in the Unicode character set

Page 19: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

19

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 techniqueskeyword encodingrun-length encodingHuffman encoding

Page 20: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

20

Keyword Encoding

Replace frequently used words with a single character

Page 21: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

21

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.

Page 22: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

22

Keyword Encoding

The encoded paragraph isWe 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.

Page 23: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

23

Keyword EncodingWhat did we save?

Original paragraph 656 characters

Encoded paragraph 596 characters

Characters saved60 characters

Compression ratio596/656 = 0.9085

Could we use this substitution chart for all text?

Page 24: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

24

Run-Length Encoding

A single character may be repeated over and over again in a long sequenceReplace 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

Page 25: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

25

Run-Length Encoding

Original textbbbbbbbbjjjkllqqqqqq+++++

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 textxxxxpppplkkkkkkk

This type of repetition doesn’t occur in English text; can you think of a situation where it might occur?

Page 26: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

26

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

Page 27: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

27

Huffman Encodingballboard would be1010001001001010110001111011

compression ratio

28/56

Encode roadbed

Page 28: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

28

Representing Audio Information

We perceive sound when a series of air compressions vibrate a

membrane in our ear, which sends signals to our brain

Page 29: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

29

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

Page 30: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

30

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

Page 31: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

31

Representing Audio Information

Figure 3.8 Sampling an audio signal

Some datais lost, but areasonablesound is reproduced

Page 32: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

32

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

Page 33: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

33

Representing Audio Information

Figure 3.9 A CD player reading binary information

Page 34: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

34

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)?

Page 35: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

35

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

Page 36: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

36

Representing Images and Graphics

Color is expressed as an RGB (red-green-blue) 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

Page 37: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

37

Representing Images and Graphics

Figure 3.10 Three-dimensional color space

Page 38: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

38

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 raster-

grahics formats

Page 39: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

39

Digitized Images and GraphicsBitmap formatContains the pixel color values of the image from left to right and from top to bottomGIF format (indexed color)Each image is made up of only 256 colorsJPEG formatAverages color hues over short distancesPNG formatLike GIF but achieves greater compression with wider range of color depths

Which is better for line drawings? Pictures?

Page 40: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

40

Digitized Images and Graphics

Figure 3.12 A digitized picture composed of many individual pixels

Wholepicture

Page 41: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

41

Digitized Images and Graphics

Figure 3.12 A digitized picture composed of many individual pixels

Magnified portionof the picture

See the pixels?

Page 42: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

42

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

Page 43: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

43

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

Page 44: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Computers and Electricity

Gate A device that performs a basic operation onelectrical signals

Circuits Gates combined to perform morecomplicated tasks

Page 45: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Computers and Electricity

How do we describe the behavior of gates and circuits?Boolean expressionsUses Boolean algebra, a mathematical notation for expressing two-valued logic Logic diagramsA graphical representation of a circuit; each gate has itsown symbolTruth tablesA table showing all possible input value and the associatedoutput values

Page 46: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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)

Page 47: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 48: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 49: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

OR GateAn 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

Page 50: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

XOR Gate

Figure 4.4 Various representations of an XOR gate

An XOR gate accepts two input signals

If both are the same, the output is 0; otherwise,the output is 1

Page 51: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 52: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

NAND Gate

The NAND gate accepts two input signalsIf both are 1, the output is 0; otherwise,the output is 1

Figure 4.5 Various representations of a NAND gate

Page 53: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

NOR Gate

Figure 4.6 Various representations of a NOR gate

The NOR gate accepts two input signals

If both are 0, the output is 1; otherwise, the output is 0

Page 54: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 55: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 56: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 57: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 58: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Constructing Gates

The easiest gates to create are the NOT, NAND, and NOR gates

Figure 4.9 Constructing gates using transistors

Page 59: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Circuits

Combinational circuit The input values explicitly determine the outputSequential circuit The output is a function of the input values and the

existing state of the circuitWe describe the circuit operations using

Boolean expressionsLogic diagramsTruth tables

Are you surprised?

Page 60: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Combinational Circuits

Gates are combined into circuits by using the output of one gate as the input for another

Page 61: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Combinational Circuits

Three inputs require eight rows to describe all possible input combinations

This same circuit using a Boolean expression is (AB + AC)

Page 62: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Combinational Circuits

Consider the following Boolean expression A(B + C)

Does this truth table look familiar?

Compare it with previous table

Page 63: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Combinational Circuits

Circuit equivalenceTwo 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

Page 64: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Properties of Boolean Algebra

Page 65: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Adders

At the digital logic level, addition is performed in binary

Addition operations are carried out by special circuits called, appropriately, adders

Page 66: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Adders

The result of adding two binary digits could produce a carry value

Recall that 1 + 1 = 10 in base two

Half adderA circuit that computes

the sum of two bits and produces the correct carry bit

Truth table

Page 67: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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); 9sum=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"; }

Page 68: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Adders

Circuit diagram representing a half adder

Boolean expressions

sum = A Bcarry = AB

Page 69: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Adders

Full adder

A circuit that takes the carry-in value into account

Figure 4.10 A full adder

Page 70: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Multiplexers

Multiplexer

A circuit that uses a few input control signals to determine which of several output data lines is routed to its output

Page 71: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Multiplexers

The control lines S0, S1, and S2 determine which of eight other input lines

(D0 … D7)

are routed to the output (F)

Figure 4.11 A block diagram of a multiplexer with three select control lines

Page 72: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 73: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 74: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 75: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 76: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Integrated Circuits

Integrated circuits (IC) are classified by the number of gates contained in them

Page 77: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

Integrated Circuits

Figure 4.13 An SSI chip contains independent NAND gates

Page 78: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

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

Page 79: Data Representation and Gates These slides are taken from your textbook Dale & Lewis.

University of Texas Pan Am

Dr. John P. Abraham

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