Lecture # 5 Data Representation
Today Questions: From notes/reading/life? Prepare for Quiz # 1 (Multiple Choice) 1.Introduce: How do Computers store data? 2.Explain: Data Types: Binary numbers, Integers, Floating Point, Booleans, Characters, Variables 3.Demo: Do some binary conversions: on board 4.Practice: Do some binary examples: in head, on keyboard 5.Evaluate: We will share and evaluate your conversions 6.Re-practice: Turn the crank on binary as you go to sleep Understand Data Types, Storage ReviewPrograms
Today Questions: From notes/reading/life? Prepare for Quiz # 1 (Multiple Choice) 1.Introduce: How do Computers store data? 2.Explain: Data Types: Binary numbers, Integers, Floating Point, Booleans, Characters, Variables 3.Demo: Do some binary conversions: on board 4.Practice: Do some binary examples: in head, on keyboard 5.Evaluate: We will share and evaluate your conversions 6.Re-practice: Turn the crank on binary as you go to sleep Understand Data Types, Storage ReviewPrograms
Today Questions: From notes/reading/life? Prepare for Quiz # 1 (Multiple Choice) 1.Introduce: How do Computers store data? 2.Explain: Data Types: Binary numbers, Integers, Floating Point, Booleans, Characters, Variables 3.Demo: Do some binary conversions: on board 4.Practice: Do some binary examples: in head, on keyboard 5.Evaluate: We will share and evaluate your conversions 6.Re-practice: Turn the crank on binary as you go to sleep Understand Data Types, Storage ReviewPrograms
Data Representation If we want to compare, sort and organize data, we need to have a way to represent it in a computer – electronically. Even the characters you are now reading, as words, must be able to be represented and encoded electronically and numerically. The following slides will explain how we represent and encode data in a computer, and how we manipulate and reason about it in a computer program.
How to Represent Data in a Computer
Foundations of Computing Information Data Types –Binary numbers –Integers and Floating Point –Booleans (True, False) –Characters –Variables Programs –Expressions –Assignment –Sequences
There are 10 kinds of people in the world – those who understand binary and those who do not.
Information Data Types Binary numbers Integers and Floating Point Booleans (True, False) Characters Variables
Decimal Numbers Each digit is a power of ten = 5 * *1 + 4 * * * * * * * *10,000
Binary Numbers Each Digit is a power of two = 0 * 2 0 (1)+ 1 * 2 1 (2)+ 1 * 2 2 (4)+ 0 * 2 3 (8)+ 1 * 2 4 (16) = 22
Binary Numbers Each Digit is a power of two = = 93 1 * 2 0 (1) + 0 * 2 1 (2) + 1 * 2 2 (4) + 1 * 2 3 (8) + 1 * 2 4 (16) + 0 * 2 5 (32) + 1 * 2 6 (64)
Why Binary? Any physical phenomenon that has two states can be used to store a binary number 11010= 26
Magnetism Magnetic Material Read/Write Head = 43
Voltage = 37
Holes in Paper Light = 1 Dark = = 42 Photo Sensor 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 – is a 4 bit number – 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 numbers Integers and Floating Point Booleans (True, False) Characters Variables
Integers
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
Floating point numbers Numbers with decimal points 1.23 = 0.123e = e =-0.232e-2 Stored differently (sign + fraction + exponent)
Information Binary numbers Integers and Floating Point Booleans (True, False) Characters Variables
Booleans 1 = true 0 = false
Boolean Expressions (7>3) is true ((2+4)<6) is false –Note Arithmetic Expression in Boolean Expression > Greater than < less than <= less than or equal >= greater than or equal == equal != not equal 7<=6 is false 6!=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 What is special about the order of the numbers? Type ‘ g ’ Store 103
ASCII Code for Characters A numeric character is different from its ASCII number
ASCII Code for Characters
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 ’ + 2 = ‘ C ’ ‘ g ’ - ‘ d ’ = 3 ‘ F ’ + 32 = ‘ f ’ ‘ A ’ < ‘ D ’ is true ‘ % ’ >= ‘ + ’ is false
Information Binary numbers Integers and Floating Point Booleans (True, False) Characters Variables
Variable A named place to store a value –George = 32 –Size = 17 –Weight = 120
Today Questions: From notes/reading/life? Prepare for Quiz # 1 (Multiple Choice) 1.Introduce: How do Computers store data? 2.Explain: Data Types: Binary numbers, Integers, Floating Point, Booleans, Characters, Variables 3.Demo: Do some binary conversions: on board 4.Practice: Do some binary examples: in head, on keyboard 5.Evaluate: We will share and evaluate your conversions 6.Re-practice: Turn the crank on binary as you go to sleep Understand Data Types, Storage ReviewPrograms
Binary Exercise Binary devices include: The binary number = what in decimal? How many bits are required to store the decimal number 256?
Review Binary devices include: paper and magnetic tape, disks, transistors The binary number = what in decimal? 45 How many bits are required to store the decimal number 256? 9 bits
Today Questions: From notes/reading/life? Prepare for Quiz # 1 (Multiple Choice) 1.Introduce: How do Computers store data? 2.Explain: Data Types: Binary numbers, Integers, Floating Point, Booleans, Characters, Variables 3.Demo: Do some binary conversions: on board 4.Practice: Do some binary examples: in head, on keyboard 5.Evaluate: We will share and evaluate your conversions 6.Re-practice: Turn the crank on binary as you go to sleep Understand Data Types, Storage ReviewPrograms
Programs Computer Programs make use of a these data types to perform a given task Standard arithmetic operations can be applied to manipulate the input data types and output a result