a computer is a device that: ◦ accepts input ◦ processes data ◦ stores data ◦ produces...

42

Upload: ernest-bennett

Post on 29-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for
Page 2: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

A computer is a device that:◦ Accepts input◦ Processes data◦ Stores data◦ Produces output

Input data transformed into output.

Data can be stored for repeated output.

Page 3: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Spreadsheet data graphs

3D models animation

Vocals and MIDI Song

Bar code Price of item

Card and Pin # Money from ATM

Page 4: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

How can we represent information in a way that can be stored and manipulated by a computer?

Page 5: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

External representation: computers use decimal digits (base ten), 26-character alphabet for easier human interaction via keyboard, terminal, printer

Internal representation: computers use binary system for numbers, letters, graphics, etc.

Page 6: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Internally, computers represent information as patterns of bits

A bit (binary digit) is either 0 or 1; these are symbols and have no numeric meaning

Storing a bit requires that a device can be in one (and only one) of just two states; analogous to true and false

Page 7: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Binary Numbers!!!

Sound pitch number binary number Letter number binary number Image color at each pixel number

binary number

Page 8: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for
Page 9: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Base 10 Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 e.g. 34210 =

= 3 x 102 + 4 x 101 + 2 x100

= 3 x 100 + 4 x 10 + 2 x 1

= 300 + 40 + 2

Page 10: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Base 2 Digits 0, 1 e.g. 1102 =

= 1 x 22 + 1 x 21 + 0 x 20

= 1 x 4 + 1 x 2 + 0 x 1 = 4 + 2 + 0 = 6

Page 11: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Solution: use a fixed number of digits.

But how many bits do we need?

1 binary digit 0 or 1 2 possible chars2 binary digits 00, 01, 10, 11 4 chars3 binary digits 000, 001, 010, 011, 100, 101, 110, 111 8 chars

Notice a pattern? 12, 24, 38, …the total number of character that can be

represented by n bits is2n

Page 12: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for
Page 13: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

But how many bits are needed to store n

symbols?Or, how many bits are needed to represent n

numbers?

log2n

How many bits do we need to represent 16 states, 63 states?

Page 14: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

1 bit◦ 0 ; 0◦ 1 ; 1

2 bits◦ 00 ; 0◦ 01 ; 1◦ 10 ; 2◦ 11 ;3

•3 bits

•000 ;0

•001 ;1

•010 ;2

•011 ;3

•100 ;4

•101 ;5

•110 ;6

•111 ;7

Page 15: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

01101101b◦ Bits are numbered from the right b7 b6b5b4b3b2b1b0

◦ Subscripts represent the place value bi has place value 2i

◦ Convert to decimal b7 * 27+b6*26 + b5*25 +b4*24 +b3*23 +b2*22 +b1*21 +

b0*20

Page 16: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

100 = 1 * 22 + 0 * 21 + 0 10 = 1 * 21 + 0

1

Page 17: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Binary to Decimal

10011 = 1 * 24 + 0 * 23 + 0 * 22 + 1* 21 + 1 * 20

Page 18: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Binary to Decimal

10011 = 1 * 24 + 0 * 23 + 0 * 22 + 1* 21 + 1 * 20

= 16 + 0 + 0 + 2 + 1 = 19

Page 19: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Repeatedly divide by 2, recording remainders in reverse order

e.g. 53 / 2 = 26 R 1 26 / 2 = 13 R 0 13 / 2 = 6 R 1 6 / 2 = 3 R 0 3 / 2 = 1 R 1 1 / 2 = 0 R 1 giving 110101

Page 20: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

56d = ?b 1011b = ?d

Page 21: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

1000 + 1 =? 0011 + 0010 = 011 – 010 = 1101 - 1011

Page 22: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

◦0000 ;0

◦0001 ;1

◦0010 ;2

◦0011 ;3

◦0100 ;4

◦0101 ;5

◦0110 ;6

◦0111 ;7

◦1000 ;8

◦1001 ;9

◦1010 ;10 (Ah)

◦1011 ;11 (Bh)

◦1100 ;12 (Ch)

◦1101 ;13 (Dh)

◦1110 ;14 (Eh)

◦1111 ;15 (Fh)

Page 23: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for
Page 24: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Sign Magnitude◦ use first bit as sign bit, 0 = positive 1 = negative◦ e.g. 8-bits

00000000 = 0 10000000 = −000000001 = 1 10000001 = −1

… …01111111 = 127 11111111 = −127

Problem: has two 0s. Using 2’s Complement instead

Page 25: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Two’s complement◦ if positive, use binary◦ if negative, complement bits and add one◦ e.g. −53

magnitude 00110101 (binary rep for 53)

complement 11001010 (flip each bit)

add 1 11001011 (add 1, resulting 2’s complement

rep for -53)

Page 26: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for
Page 27: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

3 bit pattern 000 ; 0 001 ; 1 010 ; 2 011 ; 3 100 ; -4 101 ; -3 110 ; -2 111 ; -1

We can use the 2’s complement code of 3 code to find that of -3And vice versa

Page 28: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Practice: 2 – 3 using 2’s complement representation as done by a computer ◦ Using 3 bit pattern 010 (2)+ 101 (-3)= 111 (-1)◦ Using 8 bit pattern

00000010 (2)+ 1111 1101 (-3)

= 1111 1111 (-1)

Page 29: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

00000000 = 000000001 = 1 11111111 = −100000010 = 2 11111110 = −2

… …01111111 = 127 10000001 = −127

10000000 = −128

Page 30: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

8-bit two’s complement range is − 27 to 27 − 1 − 128 to 127

16-bit two’s complement range is − 215 to 215 − 1 − 32,768 to 32,767

Page 31: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

When a number is too big for the range, overflow will occur

Example: with 3 bit pattern 3 + 2 using 2’s complement Two positive number add up to a negative

number, overflow Similarly, -4-3 results in a positive number,

also overflow

Page 32: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for
Page 33: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Real numbers A number with a whole part and a fractional part

◦ 103.334, 0.999999999, 37.0, and 3.14159 Positions to the right of the decimal point are the

tenths position: 10-1, 10-2 , 10-3 ... Same rules apply in binary as in decimal

◦ Decimal point is actually the radix point ◦ Positions to the right of the radix point in binary are ◦ 2-1 (one half),

2-2 (one quarter), ◦ 2-3 (one eighth)

Page 34: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

A real value in base 10 can be defined by the following formula

The representation is called floating point because the number of digits is fixed but the radix point floats

A binary floating-point value is defined by the formula

Page 35: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for
Page 36: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

A byte is 8 bits. Kilobyte (K) = 210 = 1,024 bytes Megabyte (Mb) = 220 = 1,048,576 bytes Gigabyte (Gb) = 230 = 1,073,741,824

bytes

Page 37: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Character Representation

Page 38: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Assign a code to each character ASCII

American Standard Code for Information Interchange 8 bits per character 256 possible codes with 8 bits

Unicode, 16 bits per character International language coding standard Superset of ASCII

Page 39: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

American Standard Code for Information Interchange (ASCII ) defines 256 symbols that can be stored in a byte. Each symbol corresponds to a number from0 -- 255

SymbolSymbol DecimalDecimal BinaryBinary

@@ 6464 0100000001000000

AA 6565 0100000101000001

BB 6666 0100001001000010

CC 6767 0100001101000011

DD 6868 0100010001000100

EE 6969 0100010101000101

FF 7070 0100011001000110

GG 7171 0100011101000111

HH 7272 0100100001001000

Page 40: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Code Value Letter 0 Null character

1 - 31 Special Control Characters 10 \n = New line

32 Space33-47, 58-64, 91-96 Punctuation48 - 57 0 - 965 - 90 A - Z97 - 122 a - z

Page 41: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for

Digit Dec Hex 0 48 30 1 49 31 … … … 9 57 39

Page 42: A computer is a device that: ◦ Accepts input ◦ Processes data ◦ Stores data ◦ Produces output Input data transformed into output. Data can be stored for