[301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used...

107
[301] Bits and Memory Tyler Caraza-Harter

Transcript of [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used...

Page 1: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

[301] Bits and MemoryTyler Caraza-Harter

Page 2: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Ones and Zeros011111111101010110001100100110110000100100011001101011010100010111011000000011001110101110111100011010101001001100011000100110001010111010110001010011101000100110100000111000010110011111110000111011011111010000011110000010101001101001011100011110100010011101001110001111111010111110011010110111110001111000111100010010110010110110100001010110111000001110011011010101111111100001001110111100011110111010000001100010111111011101110100100001000001101111010111011100100100011010010110111010001111011000011100011111111101011111100011011111011010100110110001011111010001101000101111011000000100000100101100011000011000001100101001111101110101010010110101010011000001100000100011001001101000001010110000111111101010001111101111000001001101000001010100111100010001110001011111000001111110010101011101011101001110100100111110110000010000010110101000100111011111000010111000111000010011010010111001111001111011111100110011011001011110000110110010010001101011011001110101000001100000001010100111101010100101111100000000

Computers “speak” ones and zeros (called bits)

Page 3: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Ones and Zeros011111111101010110001100100110110000100100011001101011010100010111011000000011001110101110111100011010101001001100011000100110001010111010110001010011101000100110100000111000010110011111110000111011011111010000011110000010101001101001011100011110100010011101001110001111111010111110011010110111110001111000111100010010110010110110100001010110111000001110011011010101111111100001001110111100011110111010000001100010111111011101110100100001000001101111010111011100100100011010010110111010001111011000011100011111111101011111100011011111011010100110110001011111010001101000101111011000000100000100101100011000011000001100101001111101110101010010110101010011000001100000100011001001101000001010110000111111101010001111101111000001001101000001010100111100010001110001011111000001111110010101011101011101001110100100111110110000010000010110101000100111011111000010111000111000010011010010111001111001111011111100110011011001011110000110110010010001101011011001110101000001100000001010100111101010100101111100000000

Computers “speak” ones and zeros (called bits)

what about…

Page 4: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Ones and Zeros011111111101010110001100100110110000100100011001101011010100010111011000000011001110101110111100011010101001001100011000100110001010111010110001010011101000100110100000111000010110011111110000111011011111010000011110000010101001101001011100011110100010011101001110001111111010111110011010110111110001111000111100010010110010110110100001010110111000001110011011010101111111100001001110111100011110111010000001100010111111011101110100100001000001101111010111011100100100011010010110111010001111011000011100011111111101011111100011011111011010100110110001011111010001101000101111011000000100000100101100011000011000001100101001111101110101010010110101010011000001100000100011001001101000001010110000111111101010001111101111000001001101000001010100111100010001110001011111000001111110010101011101011101001110100100111110110000010000010110101000100111011111000010111000111000010011010010111001111001111011111100110011011001011110000110110010010001101011011001110101000001100000001010100111101010100101111100000000

Computers “speak” ones and zeros (called bits)

what about…

texthello, world

Page 5: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Ones and Zeros011111111101010110001100100110110000100100011001101011010100010111011000000011001110101110111100011010101001001100011000100110001010111010110001010011101000100110100000111000010110011111110000111011011111010000011110000010101001101001011100011110100010011101001110001111111010111110011010110111110001111000111100010010110010110110100001010110111000001110011011010101111111100001001110111100011110111010000001100010111111011101110100100001000001101111010111011100100100011010010110111010001111011000011100011111111101011111100011011111011010100110110001011111010001101000101111011000000100000100101100011000011000001100101001111101110101010010110101010011000001100000100011001001101000001010110000111111101010001111101111000001001101000001010100111100010001110001011111000001111110010101011101011101001110100100111110110000010000010110101000100111011111000010111000111000010011010010111001111001111011111100110011011001011110000110110010010001101011011001110101000001100000001010100111101010100101111100000000

Computers “speak” ones and zeros (called bits)

what about…

texthello, world

numbers3.14159…

Page 6: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Ones and Zeros011111111101010110001100100110110000100100011001101011010100010111011000000011001110101110111100011010101001001100011000100110001010111010110001010011101000100110100000111000010110011111110000111011011111010000011110000010101001101001011100011110100010011101001110001111111010111110011010110111110001111000111100010010110010110110100001010110111000001110011011010101111111100001001110111100011110111010000001100010111111011101110100100001000001101111010111011100100100011010010110111010001111011000011100011111111101011111100011011111011010100110110001011111010001101000101111011000000100000100101100011000011000001100101001111101110101010010110101010011000001100000100011001001101000001010110000111111101010001111101111000001001101000001010100111100010001110001011111000001111110010101011101011101001110100100111110110000010000010110101000100111011111000010111000111000010011010010111001111001111011111100110011011001011110000110110010010001101011011001110101000001100000001010100111101010100101111100000000

Computers “speak” ones and zeros (called bits)

what about…

texthello, world

images

numbers3.14159…

Page 7: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Ones and Zeros011111111101010110001100100110110000100100011001101011010100010111011000000011001110101110111100011010101001001100011000100110001010111010110001010011101000100110100000111000010110011111110000111011011111010000011110000010101001101001011100011110100010011101001110001111111010111110011010110111110001111000111100010010110010110110100001010110111000001110011011010101111111100001001110111100011110111010000001100010111111011101110100100001000001101111010111011100100100011010010110111010001111011000011100011111111101011111100011011111011010100110110001011111010001101000101111011000000100000100101100011000011000001100101001111101110101010010110101010011000001100000100011001001101000001010110000111111101010001111101111000001001101000001010100111100010001110001011111000001111110010101011101011101001110100100111110110000010000010110101000100111011111000010111000111000010011010010111001111001111011111100110011011001011110000110110010010001101011011001110101000001100000001010100111101010100101111100000000

Computers “speak” ones and zeros (called bits)

what about…

texthello, world

images

video numbers3.14159…

Page 8: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Ones and Zeros011111111101010110001100100110110000100100011001101011010100010111011000000011001110101110111100011010101001001100011000100110001010111010110001010011101000100110100000111000010110011111110000111011011111010000011110000010101001101001011100011110100010011101001110001111111010111110011010110111110001111000111100010010110010110110100001010110111000001110011011010101111111100001001110111100011110111010000001100010111111011101110100100001000001101111010111011100100100011010010110111010001111011000011100011111111101011111100011011111011010100110110001011111010001101000101111011000000100000100101100011000011000001100101001111101110101010010110101010011000001100000100011001001101000001010110000111111101010001111101111000001001101000001010100111100010001110001011111000001111110010101011101011101001110100100111110110000010000010110101000100111011111000010111000111000010011010010111001111001111011111100110011011001011110000110110010010001101011011001110101000001100000001010100111101010100101111100000000

Computers “speak” ones and zeros (called bits)

what about…

texthello, world

imagesmusic

video numbers3.14159…

Page 9: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Ones and Zeros011111111101010110001100100110110000100100011001101011010100010111011000000011001110101110111100011010101001001100011000100110001010111010110001010011101000100110100000111000010110011111110000111011011111010000011110000010101001101001011100011110100010011101001110001111111010111110011010110111110001111000111100010010110010110110100001010110111000001110011011010101111111100001001110111100011110111010000001100010111111011101110100100001000001101111010111011100100100011010010110111010001111011000011100011111111101011111100011011111011010100110110001011111010001101000101111011000000100000100101100011000011000001100101001111101110101010010110101010011000001100000100011001001101000001010110000111111101010001111101111000001001101000001010100111100010001110001011111000001111110010101011101011101001110100100111110110000010000010110101000100111011111000010111000111000010011010010111001111001111011111100110011011001011110000110110010010001101011011001110101000001100000001010100111101010100101111100000000

Computers “speak” ones and zeros (called bits)

what about…

texthello, world

imagesmusic

video numbers3.14159…

Intuitively, people used to believe all ofthese different types of information were

fundamentally different

Page 10: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Information TheoryClaud Shannon invented information theory in 1948, with bits as basic unit of information.

Before Shannon, there was precious little sense of information as an idea, a measurable quantity, an object fitted out for hard science.

Before Shannon, information was a telegram, a photograph, a paragraph, a song.

After Shannon, information was entirely abstracted into bits.

The sender no longer mattered, the intent no longer mattered, the medium no longer mattered, not even the meaning mattered: a phone conversation, a snatch of Morse telegraph, a page from a detective story, were all brought under a common code.

~ A Mind at Play, by Jimmy Soni and Rob Goodman

Page 11: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Learning Objectives

What is a bit? A byte? How to quantify them?

How can we use simple bits to represent everything?

How are bits stored in memory?

How can we store instructions in memory?

Page 12: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Today's Topics

Binary• Bits, bytes• Quantifying bytes

Memory Organization

Data representation

Page 13: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What is a bit?

A bit is just a 0 or a 1

Page 14: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Why the name “bit”?

In the decimal number system, with have ten “digits”• 0, 1, 2, 3, 5, 6, 7, 8, 9

Page 15: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Why the name “bit”?

In the decimal number system, with have ten “digits”• 0, 1, 2, 3, 5, 6, 7, 8, 9

In a “binary” system• Two possibilities: 0 or 1

Page 16: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Why the name “bit”?

In the decimal number system, with have ten “digits”• 0, 1, 2, 3, 5, 6, 7, 8, 9

In a “binary” system• Two possibilities: 0 or 1• Binary is general word beyond scope of computing

Binary Start System

https://www.space.com/22509-binary-stars.html

Page 17: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Why the name “bit”?

In the decimal number system, with have ten “digits”• 0, 1, 2, 3, 5, 6, 7, 8, 9

In a “binary” system• Two possibilities: 0 or 1• Binary is general word beyond scope of computing

A “bit” is short for “binary digit”

Binary Start System

https://www.space.com/22509-binary-stars.html

Page 18: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Why use bits in computing?

Why not decimal? (make it easier for humans)

Or something else, like 12? (divisible by many things)

Page 19: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Why use bits in computing?

Why not decimal? (make it easier for humans)

Or something else, like 12? (divisible by many things)

Reason 1: elegance • 2 different symbols in the minimum possible

Page 20: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Why use bits in computing?

Why not decimal? (make it easier for humans)

Or something else, like 12? (divisible by many things)

Reason 1: elegance • 2 different symbols in the minimum possible

Reason 2: electronics • computers are built from

transistors and capacitors• 0/1 maps nicely to on/off,

open/closed, charged/uncharged

https://www.build-electronic-circuits.com/how-transistors-work/

Page 21: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What if you want more than 2 values?

Use more bits!

1 bit gives 2 values: 0, 1

2 bits gives 4 values: 00, 01, 10, 11

3 bits gives 8 values: 000, 001, 010, 011, 100, 101, 110, 111

N bits gives 2N values

Page 22: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What is a byte?

A byte is just 8 bits

Page 23: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What is a byte?

A byte is just 8 bits

For example: 10101010

Page 24: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What is a byte?

A byte is just 8 bits

For example: 10101010

How many different byte values are there?

Page 25: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Today's Topics

Binary• Bits, bytes• Quantifying bytes

Memory Organization

Data representation

Page 26: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Computers can process large numbers of bytes!

Metric system commonly used• Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes• Abbreviate:

kB (kilobyte, thousand), MB (megabyte, million), GB (gigabyte, billion), TB (terabyte, trillion)

Page 27: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Computers can process large numbers of bytes!

Metric system commonly used• Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes• Abbreviate:

kB (kilobyte, thousand), MB (megabyte, million), GB (gigabyte, billion), TB (terabyte, trillion)

These metrics are used for speed and space• Capacity: my hard drive can store 500 GB of data• Throughput: I can save 100 MB of data per second to by hard

drive

Page 28: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Computers can process large numbers of bytes!

Metric system commonly used• Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes• Abbreviate:

kB (kilobyte, thousand), MB (megabyte, million), GB (gigabyte, billion), TB (terabyte, trillion)

These metrics are used for speed and space• Capacity: my hard drive can store 500 GB of data• Throughput: I can save 100 MB of data per second to by hard

drive (sometimes written MB/s or MBps)

Page 29: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Computers can process large numbers of bytes!

Metric system commonly used• Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes• Abbreviate:

kB (kilobyte, thousand), MB (megabyte, million), GB (gigabyte, billion), TB (terabyte, trillion)

These metrics are used for speed and space• Capacity: my hard drive can store 500 GB of data• Throughput: I can save 100 MB of data per second to by hard

drive (sometimes written MB/s or MBps)

What is the fastest you could fill up this hard drive, if it starts empty?

Page 30: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Gotcha 1: powers of 2

In computing, we often use 1024 instead of 1000• 1024 is a “round number” in binary, because it is 210• Just like 1000 is round in decimal because it is 10

Page 31: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Gotcha 1: powers of 2

In computing, we often use 1024 instead of 1000• 1024 is a “round number” in binary, because it is 210• Just like 1000 is round in decimal because it is 10

For example• So a kilobyte might mean 1024 bytes instead of 1000 bytes• A megabyte might mean 1,048,576 bytes (instead of 1,000,000)

Page 32: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Gotcha 1: powers of 2

In computing, we often use 1024 instead of 1000• 1024 is a “round number” in binary, because it is 210• Just like 1000 is round in decimal because it is 10

For example• So a kilobyte might mean 1024 bytes instead of 1000 bytes• A megabyte might mean 1,048,576 bytes (instead of 1,000,000)• Note: the difference in interpretations is relatively small

Page 33: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Gotcha 2: “b” vs “B”

What is faster, 80 Mbps, or 20 MBps?• A little “b” means bits• A capital “B” means bytes

Page 34: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Gotcha 2: “b” vs “B”

What is faster, 80 Mbps, or 20 MBps?• A little “b” means bits• A capital “B” means bytes• 1 byte = 8 bits, so 80 Mbps is actually 10 MBps

Page 35: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Gotcha 2: “b” vs “B”

What is faster, 80 Mbps, or 20 MBps?• A little “b” means bits• A capital “B” means bytes• 1 byte = 8 bits, so 80 Mbps is actually 10 MBps

Bits are often used for networking, and bytes for storage

Example ad from https://www.spectrum.com/internet.html

This suggests you could download 12.5 MB of data

per second.

Page 36: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Today's Topics

Binary

Memory Organization

Data representation• Numbers• Colors and images• Text

Page 37: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

RAM: Random Access Memory

Memory cell• circuit that stores 1 bit of information• often based on capacitors• low voltage is 0, high voltage is 1

Page 38: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

RAM: Random Access Memory

Memory cell• circuit that stores 1 bit of information• often based on capacitors• low voltage is 0, high voltage is 1

Memory a lot of memory cells!• Typically billions (for gigabytes of memory)

lots of tiny capacitors

these are built in, and don’t actually look like this in the chip

Page 39: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

RAM: Random Access Memory

Memory cell• circuit that stores 1 bit of information• often based on capacitors• low voltage is 0, high voltage is 1

Memory a lot of memory cells!• Typically billions (for gigabytes of memory)• How to find the right bits you need to access?

Page 40: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

RAM: Random Access Memory

Memory cell• circuit that stores 1 bit of information• often based on capacitors• low voltage is 0, high voltage is 1

Memory a lot of memory cells!• Typically billions (for gigabytes of memory)• How to find the right bits you need to access?

give groups of bits/bytes addresses

Page 41: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Addresses

bits in memory …0000111101010101…

voltage …lowlowlowlowhighhighhighhighlowhighlowhighlowhighlowhigh…

Page 42: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Addresses

bits in memory …0000111101010101…

addresses

150

151

voltage …lowlowlowlowhighhighhighhighlowhighlowhighlowhighlowhigh…

Page 43: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Addresses

bits in memory …0000111101010101…

addresses

150

151

voltage …lowlowlowlowhighhighhighhighlowhighlowhighlowhighlowhigh…

request bits at address 150

Page 44: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Addresses

bits in memory …0000111101010101…

addresses

150

151

voltage …lowlowlowlowhighhighhighhighlowhighlowhighlowhighlowhigh…

request bits at address 150

get back 00001111

Page 45: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Today's Topics

Binary

Memory Organization

Data representation• Numbers• Colors and images• Text• Instructions

Page 46: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Data representation

ChallengeHow can we use ones and zeros (many of them)

to represent a wide variety of data?

Page 47: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Today's Topics

Binary

Memory Organization

Data representation• Numbers• Colors and images• Text• Instructions

Page 48: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Types of numbers

numbers

imaginary

real

integers

other

whole numbers

other

Page 49: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Types of numbers

numbers

imaginary

real

integers

other

whole numbers

other

0, 1, 2, 3, 4, …

Page 50: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

Page 51: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

one’s placeten’s placehundred’s placethousand’s place

Page 52: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

one’s placeten’s placehundred’s placethousand’s place

= 0x1000 + 3x100 + 0x10 + 1x1

Page 53: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

one’s placeten’s placehundred’s placethousand’s place

= 0x1000 + 3x100 + 0x10 + 1x1

Step up by factors of tenbecause we have ten digits

Page 54: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

one’s placeten’s placehundred’s placethousand’s place

= 0x1000 + 3x100 + 0x10 + 1x1

1011bits (binary):

Step up by factors of tenbecause we have ten digits

Number only uses 0’s and 1’s (NOT thousand and eleven)

Page 55: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

one’s placeten’s placehundred’s placethousand’s place

= 0x1000 + 3x100 + 0x10 + 1x1

1011bits (binary):

one’s placetwo’s placefour’s placeeight’s place

Step up by factors of tenbecause we have ten digits

Page 56: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

one’s placeten’s placehundred’s placethousand’s place

= 0x1000 + 3x100 + 0x10 + 1x1

1011bits (binary):

one’s placetwo’s placefour’s placeeight’s place

Step up by factors of twobecause we have two digits

Step up by factors of tenbecause we have ten digits

Page 57: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

one’s placeten’s placehundred’s placethousand’s place

= 0x1000 + 3x100 + 0x10 + 1x1

1011bits (binary):

one’s placetwo’s placefour’s placeeight’s place

= 1x8 + 0x2 + 1x2 + 1x1

Step up by factors of twobecause we have two digits

Step up by factors of tenbecause we have ten digits

Page 58: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

one’s placeten’s placehundred’s placethousand’s place

= 0x1000 + 3x100 + 0x10 + 1x1

1011bits (binary):

one’s placetwo’s placefour’s placeeight’s place

= 1x8 + 0x2 + 1x2 + 1x1 = eleven

Step up by factors of twobecause we have two digits

Step up by factors of tenbecause we have ten digits

Page 59: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Base ten vs two example

0301digits (decimal):

one’s placeten’s placehundred’s placethousand’s place

= 0x1000 + 3x100 + 0x10 + 1x1

1011bits (binary):

one’s placetwo’s placefour’s placeeight’s place

= 1x8 + 0x2 + 1x2 + 1x1 = eleven

Step up by factors of twobecause we have two digits

Step up by factors of tenbecause we have ten digits

What decimal number is represented by these bits? 11001

Page 60: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Types of numbers

numbers

imaginary

real

integers

other

whole numbers

other

0, 1, 2, 3, 4, …

How to handle negatives?

Page 61: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Types of numbers

numbers

imaginary

real

integers

other

…, -3, -2, -1, 0, 1, 2, 3, …

Page 62: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Negative binary numbers

eleven: 1011

Page 63: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Negative binary numbers

eleven: 1011

negative eleven: -1011

Page 64: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Negative binary numbers

eleven: 1011

negative eleven: -1011

Problem: computers know “0” and “1” What is this “-” thing?

Page 65: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Negative binary numbers

eleven: 1011

negative eleven: -1011

Problem: computers know “0” and “1” What is this “-” thing?

Discuss approaches to representing negative integers with only 0’s and 1’s with your neighbor

Page 66: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

One representation scheme

01011 is eleven

11011 is negative eleven

Page 67: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

One representation scheme

01011 is eleven

11011 is negative eleven

main number

Page 68: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

One representation scheme

01011 is eleven

11011 is negative eleven

main number

0: positive 1: negative

Page 69: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

One representation scheme

01011 is eleven

11011 is negative eleven

main number

0: positive 1: negative

One oddity: 00000 and 10000 are two different ways to say the same number, zero. In practice, most computers

use a slightly more complicated representation.

Page 70: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Today's Topics

Binary

Memory Organization

Data representation• Numbers• Colors and images • Text• Instructions

Page 71: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Representing color

All colors of light are a combination of red, green, and blue• Of varying intensities• Sometimes abbreviated RGB• Maximum intensity of all three is white

Page 72: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Representing color

All colors of light are a combination of red, green, and blue• Of varying intensities• Sometimes abbreviated RGB• Maximum intensity of all three is white

How to represent intensity of one of these primary colors?

Page 73: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Red intensity

Strategy• Strategy: use whole numbers (already know how to represent

these as bits)• Small number: less red• Big number: more red

0000 111110000100 1100

Page 74: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Back to colors

Strategy• Encode final color as mix of three intensities

111110000000 = ????

Page 75: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Back to colors

Strategy• Encode final color as mix of three intensities

111110000000 = ????

red green blue

Page 76: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Back to colors

Strategy• Encode final color as mix of three intensities

111110000000 = orange

red green blue result

Page 77: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Back to colors

Strategy• Encode final color as mix of three intensities• We can represent many colors with 12 bits now

111110000000 = orange

red green blue result

Page 78: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What about images?

Strategy• Break into a bunch of small squares,

called pixels• Record color of each pixel

Page 79: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What about images?

Strategy• Break into a bunch of small squares,

called pixels• Record color of each pixel

pixel 1101010000100

Page 80: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What about images?

Strategy• Break into a bunch of small squares,

called pixels• Record color of each pixel

pixel 2101010000100 101010010100

Page 81: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What about images?

Strategy• Break into a bunch of small squares,

called pixels• Record color of each pixel

pixel 3101010000100 101010010100 101010010101

Page 82: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

What about images?

Strategy• Break into a bunch of small squares,

called pixels• Record color of each pixel

101010000100 101010010100 101010010101 …

Page 83: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

A note on breaking down problems

Problem: how to represent images as 1’s and 0’s?• Can we make it simpler?

Page 84: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

A note on breaking down problems

Problem: how to represent images as 1’s and 0’s?• Can we make it simpler?

We can represent images as a bunch of color values

We can represent a color value as a three integers

We can represent an integer as a bunch of bits

Page 85: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

A note on breaking down problems

Problem: how to represent images as 1’s and 0’s?• Can we make it simpler?

We can represent images as a bunch of color values

We can represent a color value as a three integers

We can represent an integer as a bunch of bits

Chain these representations together to represent images as bits!

Page 86: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Today's Topics

Binary

Memory Organization

Data representation• Numbers• Colors and images• Text• Instructions

Page 87: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

How can we encode text, like “Hello World”, using just bytes?

Page 88: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Morse Code

.... . .-.. .-.. ---

Page 89: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Morse Code

.... . .-.. .-.. ---

H E L L O

Page 90: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Morse Code

.... . .-.. .-.. ---

H E L L O

We can represent text as dots and dashes. Any ideas on how we can further encode dots and dashes as bits?

Page 91: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Morse Code

.... . .-.. .-.. ---

H E L L O

0000 0 0100 0100 111

Page 92: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Morse Code

.... . .-.. .-.. ---

H E L L O

0000 0 0100 0100 111

What’s wrong with this?

Page 93: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Morse Code

.... . .-.. .-.. ---

H E L L O

0000 0 0100 0100 111

is this “H” or “EEEE” ?

Page 94: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Morse Code

.... . .-.. .-.. ---

H E L L O

0000 0 0100 0100 111

is this “H” or “EEEE” ?

Morse code depends on spaces, which aren’t bits! (similar to problem we encountered with “-”)

Page 95: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

A popular encoding: ASCII

American Standard Code for Information Interchange• We know how to encode integers as bits

Page 96: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

A popular encoding: ASCII

American Standard Code for Information Interchange• We know how to encode integers as bits• Assign every English letter (upper and lower case), digit, and

various other symbols a number between 0 and 127• To save text as bits, convert each character to a number, then

convert that number to bits

Page 97: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

http://www.asciitable.com/

Page 98: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

A popular encoding: ASCII

American Standard Code for Information Interchange• We know how to encode integers as bits• Assign every English letter (upper and lower case), digit, and

various other symbols a number between 0 and 127• To save text as bits, convert each character to a number, then

convert that number to bits

Problem: to be generally useful for text in many languages, 127 is not nearly enough.

¡We need more characters!

Page 99: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Unicode

A numbered set of characters for many languages• The number assigned a character is its “code point”• Has 137,439 characters• Supports 146 different scripts

(a script is the set of characters used in a language; different languages may share the same script)

• Many of the changes from Python 2 to Python 3 are related to making unicode the default

Page 100: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Unicode

A numbered set of characters for many languages• The number assigned a character is its “code point”• Has 137,439 characters• Supports 146 different scripts

(a script is the set of characters used in a language; different languages may share the same script)

• Many of the changes from Python 2 to Python 3 are related to making unicode the default

n has code point 110

ñ has code point 241

Page 101: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Code points to bits

Unicode has multiple ways to convert code points to bits• Useful for compatibility/efficiency

n

ñ

Character Code Point Bits

110

241

utf-3211111111111111100000000000000000 01101110000000000000000000000000

utf-3211111111111111100000000000000000 11110001000000000000000000000000

utf-32 is a way to convert code points to bits. If you use the same number of bits for every code point, you need lots of bits (because there are many code points)

Page 102: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Code points to bits

Unicode has multiple ways to convert code points to bits• Useful for compatibility/efficiency

n

ñ

Character Code Point Bits

110

241

01101110utf-8

utf-3211111111111111100000000000000000 01101110000000000000000000000000

1100001110110001utf-8

utf-3211111111111111100000000000000000 11110001000000000000000000000000

utf-8 uses shorter sequences of bits for some characters and longer sequences for others. Depending on what characters you use, this may save bits.

Page 103: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Today's Topics

Binary

Memory Organization

Data representation• Numbers• Colors and images• Text• Instructions

Page 104: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Storing code in memory

Programs are also represented in memory

A program is just a bunch of instructions• Instructions are things like add, subtract, multiply, compare

Page 105: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Storing code in memory

Programs are also represented in memory

A program is just a bunch of instructions• Instructions are things like add, subtract, multiply, compare

Encoding strategy• Give each instruction a number, for example:

1: add2: multiply3: compare…

Page 106: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Storing code in memory

Programs are also represented in memory

A program is just a bunch of instructions• Instructions are things like add, subtract, multiply, compare

Encoding strategy• Give each instruction a number, for example:

1: add2: multiply3: compare…

• We already know how to represent numbers as bits, so we can also represent the instructions that make up a program as bits

Page 107: [301] Bits and Memory · Computers can process large numbers of bytes! Metric system commonly used • Just like a kilogram is 1000 grams, a kilobyte is 1000 bytes • Abbreviate:

Conclusion

Today we learned about• Binary numbers• How RAM stores binary numbers• Units for expressing capacity and throughput• All information can be represented with bits!• Encoding strategies for numbers, images, text, and programs- the details don’t matter for this class. Just get a sense how to

break down the problem of converting different types of data to ones and zeros