23
CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson [email protected] Department of Computer and Information Science, IUPUI

CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson [email protected] Department of Computer and Information Science, IUPUI

Embed Size (px)

Citation preview

Page 1: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

CSCI N201Programming Concepts and Database

3 – Essence of Computing

Lingma [email protected]

Department of Computer and Information Science, IUPUI

Page 2: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Definition of ComputerDefinition of Computer

• Universal• Information• Manipulator

Page 3: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Definition of Definition of ComputerComputer

• Universal– Works with all kinds of information

• Words, maths, images, videos

– Performs different tasks• Games, create a document read books, long

distance calls, modify images…

– Very few limitations• Do anything with any kind of information

Page 4: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Definition of Definition of ComputerComputer

• Information– Seems to be able to work with anything– Actually very limited

• All translated into 1s and 0s

– Tiny pieces of data combined into complex information

Page 5: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Definition of Definition of ComputerComputer

• Manipulator– Seem able to do anything with data– Actually very limited

• Come down to a few basic operations

– Simple commands combined into complex instructions

Page 6: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Computer and Computer and InformationInformation

• Information limited to on/off impulses, like a light switch

• Light switch demo– http://wally.cs.iupui.edu/n100/update/binLights.html– One light switch

• 1 – on, 0 – off• Two messages – Have a lecture class today? (on: yes;

off: no)

– Two light switches• Switch one – Have a lecture class today? (on: yes; off:

no)• Switch two – Have a lab class today? (on: yes; off: no)• How many messages can two switches send?

Page 7: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Computer and Computer and InformationInformation

– Three light switches• Switch one – Have a lecture class today? (on: yes; off:

no)• Switch two – Have a lab class today? (on: yes; off: no)• Switch three – Have a quiz today? (on: yes; off: no)• How many messages can two switches send?

– Adding each extra switch will double the number of messages

– 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, ….

Page 8: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Computer and Computer and InformationInformation

• Related to how computers store information– Brick counter demo– http://wally.cs.iupui.edu/n100/update/legoMover.html– Represent 1, 2, 4, 8– How to represent other numbers? (0 – 15)– How to represent more numbers?

Page 9: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Binary ConversionBinary Conversion

• Converting from binary to base 10– Use a spreadsheet– E.g. 1: 101

• Brick Demo

Page 10: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Binary ConversionBinary Conversion

– E.g. 2: 1101– E.g. 3: 1010– Try it yourself!

Page 11: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Binary ConversionBinary Conversion

• How are binary numbers related to base 10 numbers?

• E.g., 367

Page 12: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Binary ConversionBinary Conversion

• Binary numbers, base 2. Able to deal with any number with the power of 2

• Binary 101 = 1*2^2 + 0*2^1 + 1*2^0 = 5• Decimal 101 = 1*10^2 + 0*10^1 + 1*10^0 = 101

Page 13: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Binary ConversionBinary Conversion

• Base 10, 0 – 9 digits, add more digits as numbers grow

• Base 2, 0 – 1, add more switches as numbers grow

Page 14: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Binary ConversionBinary Conversion

• Converting from base 10 to binary– Use a spreadsheet

– Try it yourself!

Page 15: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Binary ConversionBinary Conversion

• Converting from base 10 to binary– Large numbers

• E.g., 34What is the result from using spreadsheet?

34/2 = 17 with a remainder of 017/2 = 8 with a remainder of 18/2 = 4 with a remainder of 04/2 = 2 with a remainder of 02/2 = 1 with a remainder of 01/2 = 0 with a remainder of 1 Result: 100010 (get the remainder

backwards)• E.g. 157

Page 16: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Computer Definition Computer Definition RevisitRevisit

• Information– Only deal with 1s and 0s

Binary conversion readings:http://www.cs.iupui.edu/~n241/readings/

binconv.html

Page 17: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Computer Definition Computer Definition RevisitRevisit

• Operation– Very limited– Only three logical operations

• AND, OR, NOT

Page 18: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Basic Logic GatesBasic Logic Gates

• True or False conditions– E.g.I have a football. – True, False?– Why True or False ? – 1 or 0

• Add logic operations– E.g. I have a football and a baseball.

I have a football or a baseball. I do not have a football.

– E.g. A hardware device example

Page 19: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Basic Logic GatesBasic Logic Gates

• Truth tables– Logical AND

A B Result

F F F

F T F

T F F

T T T

Page 20: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Basic Logic GatesBasic Logic Gates

• Truth tables– Logical OR

A B Result

F F F

F T T

T F T

T T T

Page 21: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Basic Logic GatesBasic Logic Gates

• Truth tables– Logical NOT

A NOT A

F T

T F

Page 22: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Basic Logic GatesBasic Logic Gates

• These devices are called gates• Turning them into electronic devices, we

can put them together to build electronic circuit boards and components, and make computers do different jobs, such as adding or subtracting binary numbers

• Everything comes down to the operations of the three logic gates

Page 23: CSCI N201 Programming Concepts and Database 3 – Essence of Computing Lingma Acheson linglu@iupui.edu Department of Computer and Information Science, IUPUI

Basic Logic GatesBasic Logic Gates

• Practice:– If you are a student of computer science, or if you

are a freshman, you can access the computers in this lab.

• Can I access the computers in this lab if I am a first year computer science student?

– If ((midterm>80) and (final>90)) then grade=“A”• Will Sam get an “A” if his midterm score is 85 and final is

89?

– If (count <3) then let the user try again.• Mary has tried logging to the account three times, will she

be allowed to try again?

– If you are taller than 4ft, or you are over 16 years old, then you can ride the roller coaster.

• Peter is 15 years old, can he ride the roller coaster?