information and programs. foundations of computing information –binary numbers –integers and...

37
Information and Programs

Upload: christal-wright

Post on 30-Dec-2015

215 views

Category:

Documents


2 download

TRANSCRIPT

Information and Programs

Foundations of Computing

• Information– Binary numbers– Integers and Floating Point– Booleans (True, False)– Characters– Variables

• Programs– Expressions– Assignment– Sequences

Information

Binary numbers

• Integers and Floating Point

• Booleans (True, False)

• Characters

• Variables

Decimal Numbers

• Each digit is a power of ten12345 =

5 * 1 +

4 * 10 +

3 * 100 +

2 * 1000 +

1 * 10,000

Binary Numbers

• Each Digit is a power of two10110 =

1 * 0 +

2 * 1 +

4 * 1 +

8 * 0 +

16 * 1

= 22

Binary Numbers

• Each Digit is a power of two1011101 =

= 93

1 * 1 +

2 * 0 +

4 * 1 +

8 * 1 +

16 * 1+

32 * 0 +

64 * 1

Why Binary?

• Any physical phenomenon that has two states can be used to store a binary number

11010 = 26

Magnetism

+ - + - + +

MagneticMaterial

Read/Write Head1

101011 = 43

Voltage

+5 +5 +50 0 0

100101 = 37

Holes in PaperLight = 1Dark = 0

101010 = 42

PhotoSensor

Light

Binary Students

• Male = 0

• Female = 1

Why Binary?

• Any physical phenomenon that has two states can be used to store a binary number

• Each binary digit is called a BIT– 1010 - is a 4 bit number– 01010100 - is an 8 bit number

• An 8 bit number is called a BYTE

Size of a Binary Number

• How many different numbers can you store in 2 bits?

• How many can you store in 8 bits?• In general, 2(number of bits) numbers can be stored• How many in 10 bits?

– 1024 = 1K

• How many in 20 bits?– 1,048,576 = 1Meg

Information

• Binary numbersIntegers and Floating Point

• Booleans (True, False)

• Characters

• Variables

Integers

• 100

• 100245

• -45

Size of an Integer

• How many bits required for the number 17?

• 5 bits

• How many bits for the number 1023?

• 10 bits

Integer Expressions

• * means multiply

• / means divide

• 2*4+3 = 11

• 2*(4+3) = 14

• (7+9)/2 = 8

Floating point numbers

• Numbers with decimal points

• 1.23

• 5623.1232

• -0.00232

Floating point numbers

• Numbers with decimal points

• 1.23 = 0.123e1• 5623.1232 = 0.56231232e4• -0.00232=-0.232e-2

• Stored differently (sign + fraction + exponent)

Information

• Binary numbers

• Integers and Floating PointBooleans (True, False)

• Characters

• Variables

Booleans

• 1 = true

• 0 = false

Boolean Expressions

• (7>3) is true• ((2+4)<6) is false

> Greater than< less than<= less than or equal>= greater than or equal== equal!= not equal

7<=6 is false6!=5 is true

Information

• Binary numbers

• Integers and Floating Point

• Booleans (True, False)Characters

• Variables

ASCII Code for Characters

• Every character is defined to have an 8 bit (1 byte) number

A 65B 66C 67D 68E 69F 70G 71H 72I 73J 74K 75. . .Z 90

What is special about the order of the numbers?

a 97b 98c 99d 100e 101f 102g 103h 104I 105j 106k 107. . .z 122

Type ‘g’Store 103

ASCII Code for Characters

A 65B 66C 67D 68E 69F 70G 71H 72I 73J 74K 75. . .Z 90

A numeric character is different from its ASCII number

a 97b 98c 99d 100e 101f 102g 103h 104I 105j 106k 107. . .z 122

0 481 492 503 514 525 536 547 558 569 57

ASCII Code for Characters

A 65B 66C 67D 68E 69F 70G 71H 72I 73J 74K 75. . .Z 90

Dad32@Abc

a 97b 98c 99d 100e 101f 102g 103h 104i 105j 106k 107. . .z 122

0 481 492 503 514 525 536 547 558 569 57

. 46- 45+ 43@ 64$ 36% 37& 38 space 32* 42( 40) 41

68 97 100 51 50 64 65 98 99

What about Chinese, Sanscrit, Hebrew, Cyrillic, etc ??A 65B 66C 67D 68E 69F 70G 71H 72I 73J 74K 75. . .Z 90

a 97b 98c 99d 100e 101f 102g 103h 104I 105j 106k 107. . .z 122

0 481 492 503 514 525 536 547 558 569 57

. 46- 45+ 43@ 64$ 36% 37& 38 space 32* 42( 40) 41

What about Chinese, Sanscrit, Hebrew, Cyrillic, etc ??

• UNICODE rather than ASCII

• 2 Bytes per character– Twice as much space– 65,536 possible characters (2^16)

Expressions with characters

A 65B 66C 67D 68E 69F 70G 71H 72I 73J 74K 75. . .Z 90

a 97b 98c 99d 100e 101f 102g 103h 104I 105j 106k 107. . .z 122

0 481 492 503 514 525 536 547 558 569 57

. 46- 45+ 43@ 64$ 36% 37& 38 space 32* 42( 40) 41

‘A’ + 2 = ‘C’‘g’- ‘d’ = 3‘F’ + 32 = ‘f’

‘A’ < ‘D’ is true‘%’ >= ‘+’ is false

Information

• Binary numbers

• Integers and Floating Point

• Booleans (True, False)

• CharactersVariables

Variable

• A named place to store a value– George = 32– Size = 17– Weight = 120

Program

• A sequence of things to do

A = 75;

B = A+13;

A = A-B+3;

C = A/2 + 1;

Program

• A sequence of things to do

A = 75;

B = A+13;

A = A-B+3;

C = A/2 + 1;

A 75B ?C ?

Program

• A sequence of things to do

A = 75;

B = A+13;

A = A-B+3;

C = A/2 + 1;

A 75B 88C ?

A + 13

75 + 13 = 88

Program

• A sequence of things to do

A = 75;

B = A+13;

A = A-B+3;

C = A/2 + 1;

A -10B 88C ?

A-B+3

75 - 88 + 3 = -10

Program

• A sequence of things to do

A = 75;

B = A+13;

A = A-B+3;

C = A/2 + 1;

A -10B 88C -4

A / 2 + 1

-10 / 2 + 1 = -4

Review

• Binary numbers (using any two states)• Integers and Floating Point

– Expressions (+ - * /)

• Booleans (true, false) (< > <= >= == !=)• Characters

– ASCII, UNICODE

• Variables• Programs