Lesson4.2 u4 l1 binary squences

28
L.O: STUDENTS UNDERSTAND BINARY SEQUENCES . 35-70 minutes (1-2 class periods) DO NOW: READ Unit 4 Lab 1: Number Representation, Page 2

Transcript of Lesson4.2 u4 l1 binary squences

Page 1: Lesson4.2 u4 l1 binary squences

L.O: STUDENTS UNDERSTAND BINARY SEQUENCES.

35-70 minutes (1-2 class periods)

DO NOW:READ

Unit 4 Lab 1: Number Representation, Page 2

Page 2: Lesson4.2 u4 l1 binary squences

This data means something to a computer!

All the data in computers is stored in sequences of binary (ones and zeros)!

This BINARY SEQUENCE could be ANYTHING: A video game, medical

records, grades, a cake recipe…..IT ALL DEPENDS ON HOW THE DATA WILL BE

USED!

how any binary sequence is interpreted depends on how it

will be used.

Binary sequences are used to represent instructions to the

computer and various types of data depending on the context.

The computer program is going

through the binary sequence and thus making the turtle move

Page 3: Lesson4.2 u4 l1 binary squences

Computers store information in binary using bits and bytes. A bit is a "0" or "1". A byte is eight bits grouped together like 10001001.

Bytes have 8 places, so the left-most place is 27 (or 128).

Practice what you've learned: What is 100010012 in base 10?

Page 4: Lesson4.2 u4 l1 binary squences

Binary Sequences• bit – a single unit of data that can only have

one of two values (such as a 1 or 0)• bit rate – the amount of data (measured in

bits) that can be sent in a specific amount of time

• bandwidth – the transmission capacity of a system (measured by bit rate)

• latency – time between the transmission and the receipt of a message

Page 5: Lesson4.2 u4 l1 binary squences

Computers used to have limited memory space.We used to measure computer memory in kilobytes; one kilobyte is 210 (1,024) bytes, which is about 103,

so we call it a "kilo”.

These days, your computer memory is likely to be measured in megabytes. One megabyte is 220 (about 1 million) bytes!

Your hard drive space is likely to be measured in gigabytes, terabytes, or even petabytes. One

gigabyte is 230 (about 1 billion) bytes, one terabyte is 240 (about 1 trillion) bytes, and one petabyte is 250

(about 1 quadrillion) bytes.

As computers become more powerful, they are capable of handling more

information and doing more things!

Page 6: Lesson4.2 u4 l1 binary squences

measure amount example

bit Either a 1 or a 0 1

byte 8 bits 11011001

kilobyte 210 (1,024) bytes A couple of paragraphs

megabyte 220 (1,048,576) bytes About 1 book

gigabyte 230 (1,073,741,824) bytes

A little more than 1 CD

terabyte 240 (1,099,511,627,776) bytes

About 1,500 CDs

petabyte 250 (1,125,899,906,842,624) bytes

About 20 million filing cabinets of text

Page 7: Lesson4.2 u4 l1 binary squences

a bit is a 1 or a 0 A byte: 8 bits

11011001

1 kilobytes: 210 (1,024) bytes

2 paragraphs

1 megabyte: 220 (1,048,576) bytes

about 1 book

1 gigabyte: 230 (1,073,741, 824) bytes

a little more than 1 CD

1 terabyte: 240 (1,099,511, 627, 776) bytes

about 1500 CDs

1 petabyte: 250 (1,125,899, 906, 842, 624) bytes

about 20 million filing cabinets of text

Page 8: Lesson4.2 u4 l1 binary squences

Integers are the positive numbers, the negative

numbers and zero.Much of computing is about storing

integers and working with them!

Page 9: Lesson4.2 u4 l1 binary squences

Storing Integers:• Depending on the programming

language used, an integer might be stored with two bytes of data.• or perhaps four bytes of data allowing

for a range of about -32,768 to 32,767 (with two bytes) or -2,147,483,648 to 2,147,483,647 (with four bytes).

some programming languages use two bytes (16 bits: 16 ones and zeros) to store integers

(numbers).Two bytes can represent 216 = 65,536 different

numbers.About Half are positive, the other half is

negative and one to represent 0. from – 32,768 to 32,768

others languages use 4 bytes (32 bits: 32 ones and zeros) to store integers (numbers).

four bytes can represent 232 = 4,294,967,296 different numbers.

About Half are positive, the other half is negative and one to represent 0.

from – 2,147,438,648 to 2,147,483,647.

Page 10: Lesson4.2 u4 l1 binary squences

What about bigger numbers? • the specific size is for storing integers (two bytes,

four bytes, etc.), will limit the range of the integer values that can be stored and the mathematical operations that can be performed.

• Values that exceed this limitation may result in errors such as overflow errors because big values overflow the amount of space allocated to store one number.

What does this mean?Why do computers show this sometimes?

Page 11: Lesson4.2 u4 l1 binary squences

For You To Do:1. The factorial of a positive integer n

(written ”n!") is the product of all the integers from 1 to n. For example:

5! =1×2×3×4×5=120

Page 12: Lesson4.2 u4 l1 binary squences

Load this project, and try out these inputs:

a..b..c..d. try 200!

Note:You do not need to learn the factorial function for

this class (we are just using it to discuss big

numbers), but you will probably see it again in a

math class.

What's going on? Although 200! is very large, it's not infinite! This report is the result of the size

limitation. If the result of a computation is bigger than than the range of numbers that can be stored,

then the computer returns a special code or an overflow error.

Although you MIGHT see different results based on your computer processor,In Snap!, there are special codes for

infinity – infinity (smaller than any finite value), and "Not a Number," which is the notification used for illegal computations

such as 0/0

Page 13: Lesson4.2 u4 l1 binary squences

computers don’t “understand” English or any human language! They don’t know what an

alphabet is, they don’t even know the numbers: 2, 3, 4, 5, 6, 7, 8, 9…

All computers know are bits and bytes: ones and

zeros!

Everything you command a computer to do is turned in

BINARY!

Page 14: Lesson4.2 u4 l1 binary squences

Storing Text:• programming languages use a

specific number of bits to represent Unicode characters or integers. Unicode is a system that allows computers to store letters as integers. For example, capital A is Unicode number 65, which is 010000012

We'll learn more about Unicode in the Caesar Cipher Project in the

Cybersecurity lab, where we’ll create a program to encrypt a message!

Page 15: Lesson4.2 u4 l1 binary squences

Floating Points:• Many languages have another data type used to

represent real numbers (including decimals and numbers too big to be stored as integers) called floating point.

• A floating point is a binary version of scientific notation.

• It's called “floating point” because the decimal point "floats" to just after the first digit.

Page 16: Lesson4.2 u4 l1 binary squences

Try 30!

•e+32 is just a different way to write scientific notation.

The "e+" means "times ten to the power of" so: 2.6525285981219103e+32 =2.6525285981219103×10 32

=265,252,859,812,191,030,000,000,000,000,000

Page 17: Lesson4.2 u4 l1 binary squences

• Floating point allows computers to store very large numbers and also decimals,• but the format still has a specific

number of bits,• and that limits the range of floating

point values and mathematical operations just like with integers. • However with floating point, values that

exceed the limitation may result in round off errors instead.

Page 18: Lesson4.2 u4 l1 binary squences

Even with floating points (scientific notation) most real numbers can’t be represented exactly

• For example try

The decimal representation of 1/3 is 0.3333333333333...

It has infinitely many digits, so the closest you can come in floating point isn't exactly 1/3 ;

it gets cut off after a while.Roundoff errors can result in some pretty

weird calculations...

Page 19: Lesson4.2 u4 l1 binary squences

Try and then

• Computer arithmetic on integers is straightforward. Either you get an exactly correct integer result or, if the result won't fit in integer representation, you get an overflow error and the result is, usually, converted to floating point representation (like 30! was).

This isn't a bug with Snap!. Many other languages (like JavaScript) will report the same values for these

calculations.

By contrast, computer arithmetic on floating point numbers is hard to get exactly right. Prior to 1985, every model of

computer had a slightly different floating point format, and all of them got wrong answers to certain problems. This

situation was resolved by the IEEE 754 floating point standard, which is now used by every computer

manufacturer and has been improved several times since it was created in 1985

Page 20: Lesson4.2 u4 l1 binary squences

Programming languages have know how to interpret a bit sequence as an integer, a floating point, a text string of unicode

characters, an instruction or something else

Do you know if this binary sequence codes for bunch of integers? A text string in unicode (a sentence), Hindi? Russian? English? Another

human language? A movie? Or something else? Obviously not!

Each Programming language differs in how they do it, but there's always some extra bit sequence

that encodes the data type of any sequence of bits that tells the computer how to interpret the

sequence!

Page 21: Lesson4.2 u4 l1 binary squences

At the lowest level of software abstraction, everything in a computer is represented as a binary sequence.

For example:• A Boolean value is a single bit,

0 for false and 1 for true.• A text string is a sequence of

Unicode character codes, each of which is stored as a separate integer.

• Lists and blocks are binary sequences too.

Page 22: Lesson4.2 u4 l1 binary squences

Take it further (extension activities)

A.What's the rightmost digit in the binary representation of 15551212?

B.What's the rightmost bit ("binary digit") of 123456789?

C. Develop a rule for finding the rightmost bit of any base 10 number.

A. What's the rightmost digit in the binary representation of 15551212? 0 because 15551212 is even.

B. What's the rightmost bit ("binary digit") of 123456789? 1 because 123456789 is odd.

C. Develop a rule for finding the rightmost bit of any base 10 number. If the rightmost digit of the base 10

number is even the rightmost bit of its binary representation will be 0; if it is odd, it will be 1.

Page 23: Lesson4.2 u4 l1 binary squences

Learning Objectives:

• LO 2.1.1 Describe the variety of abstractions used to represent data. [P3]• LO 2.1.2 Explain how binary

sequences are used to represent digital data. [P5]

Page 24: Lesson4.2 u4 l1 binary squences

Enduring Understandings:

•EU 2.1 A variety of abstractions built upon binary sequences can be used to represent all digital data.

Page 25: Lesson4.2 u4 l1 binary squences

Essential Knowledge:

1. EK 2.1.1A Digital data is represented by abstractions at different levels.

2. EK 2.1.1B At the lowest level, all digital data are represented by bits.

3. EK 2.1.1C At a higher level, bits are grouped to represent abstractions, including but not limited to numbers, characters, and color.

4. EK 2.1.1D Number bases, including binary, decimal, and hexadecimal, are used to represent and investigate digital data

Page 26: Lesson4.2 u4 l1 binary squences

Essential Knowledge:• 5. EK 2.1.1E At one of the lowest levels of

abstraction, digital data is represented in binary (base 2) using only combinations of the digits zero and one.

• 6. EK 2.1.1F Hexadecimal (base 16) is used to represent digital data because hexadecimal representation uses fewer digits than binary.

• 7. EK 2.1.1G Numbers can be converted from any base to any other base.

• 8. EK 2.1.2A A finite representation is used to model the infinite mathematical concept of a number.

Page 27: Lesson4.2 u4 l1 binary squences

Essential Knowledge:

• 9. EK 2.1.2B In many programming languages, the fixed number of bits used to represent characters or integers limits the range of integer values and mathematical operations; this limitation can result in overflow or other errors.

• 10.EK 2.1.2C In many programming languages, the fixed number of bits used to represent real numbers (as floating point numbers) limits the range of floating point values and mathematical operations; this limitation can result in round off and other errors.

Page 28: Lesson4.2 u4 l1 binary squences

Essential Knowledge:• 11. EK 2.1.2D The interpretation of a binary sequence

depends on how it is used.• 12. EK 2.1.2E A sequence of bits may represent

instructions or data.• 13. EK 2.1.2F A sequence of bits may represent different

types of data in different contexts.• 14. EK 6.2.2J The bandwidth of a system is a measure of

bit rate—the amount of data (measured in bits) that can be sent in a fixed amount of time.

• 15. EK 6.2.2K The latency of a system is the time elapsed between the transmission and the receipt of a request.