1 there are 10 types of people in this world: those that understand binary numbers, and those that...

28
1 There are 10 types of people in this world: those that understand binary numbers, and those that don’t. . . Bits and Bytes

Upload: emma-lyon

Post on 26-Mar-2015

221 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

1

There are 10 types of people in this world: those that understand binary numbers, and those that don’t. . .

Bits and Bytes

Page 2: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

2

Bits and Binary Numbers• A bit is a Binary digIT – a digit that can have two values: one or

zero.• Binary numbers are composed of bits, just like decimal numbers

are composed of digits 0-9 • Binary numbers can be used to represent letters, numbers,

pictures, sound, or just about anything.• The exact same pattern of 1s and 0s might represent many

different things, depending on where it is and what program is using it.

• For instance, the bits 01000010b could represent the number 66, or the letter ‘A’, or part of a picture, or part of a sound, or. . .

• The interpretation depends on the context. This includes things like the file extension, and the program that's reading the data.

• What does coin mean?

Page 3: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

3

Decimal Numbers and Place ValueBase 10 is our old friend:

5473 = (5 * 1000) + (4 * 100) + (7 * 10) + (3 * 1)

Can also be written as:

(5 * 103) + (4 * 102) + (7 * 101) + (3 * 100)

We could use any number as a base – 10 just happens to be convenient if you have 10 fingers.

Page 4: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

4

Binary Numbers

128's 64's 32's 16's 8's 4's 2's 1's

1 0 0 1 0 1 1 1

Example: 10010111b

= (1*27) + (0*26) + (0*25) + (1*24) + (0*23) + (1*22) + (1*21) + (1*20)= 128 + 16 + 4 + 2 + 1

Base two only uses 0 and 1. The place values are powers of 2:1, 2, 4, 8, 16, 32, 64, 128, and so forth, ad infinitum.

= 151

Page 5: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

5

16's 8's 4's 2's 1's

0 0 0 0 0

0 0 0 0 1

0 0 0 1 0

0 0 0 1 1

0 0 1 0 0

0 0 1 0 1

0 0 1 1 0

0 0 1 1 1

0 1 0 0 0

0 1 0 0 1

0 1 0 1 0

And so on, ad infinitum. . .

10's 1's

0 0

0 1

0 2

0 3

0 4

0 5

0 6

0 7

0 8

0 9

1 0

Binary: Decimal:

A Binary Odometer

Page 6: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

6

ExampleConvert 198 to binary:

198 / 128 = 1, remainder is 70

70 / 64 = 1, remainder is 6

6 / 32 = 0, remainder = 6

6 / 16 = 0, remainer = 6

6 / 8 = 0, remainder = 6

6 / 4 = 1, remainder is 2

2 / 2 = 1, remainder is 0

0 / 1 = 0128's 64's 32's 16's 8's 4's 2's 1's

1 1 0 0 0 1 1 0

198 = 11000110b

Page 7: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

7

Bytes• A byte is 8 bits. 8 bits can represent 256 different

values.• Computers generally use a byte or a series of bytes

to represent information.• 16 bits will represent 256*256=65536 different

values.• 24 bits will represent 256*256*256=16,777,216

different values.• and so on. . .

Page 8: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

8

Counting Bytes: Kilo, Mega, Giga, Tera, and Lotta

Prefix Approximately? Abbrev. Exactly? How many bytes?

Kilo Thousand (103) KB 1024 1024

Mega Million (106) MB 1024 KB 1,048,576

Giga Billion (109) GB 1024 MB 1,073,741,824

Tera Trillion(1012) TB 1024 GB 1,099,511,627,776

Peta Quadrillion (1015)

PB 1024 TB 1,125,899,906,842,624

Exa Quintillion (1018)

EB 1024 PB A whole lot. . .

Zetta Sextillion (1021) ZB 1024 EB Even more. . .

Yotta Septillion (1024) YB 1024 ZB Fuggedabaddit. . .

Page 9: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

9

Hexadecimal – Base 16• An 8 bit byte is frequently

shown as a pair of hexadecimal (hex) digits.

Hex is widely used to represent colors in HTML tags: color=“#00FF0E”6 hex digits are enough to specify 16.7 million different combinations of R,G,B

dec bin hex dec bin hex

0 0000b 0x0 8 1000b 0x8

1 0001b 0x1 9 1001b 0x9

2 0010b 0x2 10 1010b 0xA

3 0011b 0x3 11 1011b 0xB

4 0100b 0x4 12 1100b 0xC

5 0101b 0x5 13 1101b 0xD

6 0110b 0x6 14 1110b 0xE

7 0111b 0x7 15 1111b 0xF

0110 1010

one byte

0x6A

4 bits: 16 different values

two hex digits:

Page 10: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

10

Decimal to Hex:

• Convert 0xBE to decimal:

0xBD = (11 * 16) + (14 * 1)

0xBE = 190

16's 1's

A D

• Convert decimal 173 to hex:

173 / 16 = 10 (0xA), remainder = 13 (0xD)

173 = 0xAD

16's 1's

B E

Hex to Decimal:

Page 11: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

11

Binary to Hex Example128's 64's 32's 16's 8's 4's 2's 1's

1 1 0 1 1 1 0 08's 4's 2's 1's 8's 4's 2's 1's

D C

Starting from the right-most bit, break the binary number into groups of 4 bits, and convert each group to the equivalent hex digit.

0xDC

Page 12: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

12

Encoding Text• Fundamentally, computers just deal with numbers. They

store letters and other characters by assigning a number for each one. Characters are generally represented in a computer as ASCII or Unicode values, where numbers are assigned to letters, digits, punctuation, etc.

Binary Decimal Symbol

00110000 48 0

00110001 49 1

00110011 50 2

… … …

01000001 65 A

01000010 66 B

01000011 67 C

… … …

Sample ASCII:

Page 13: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

13

Analog Digital

Page 14: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

14

What is Sound?Sound is variations in air pressure – air moving back and forth quickly. Your ear and your brain turn these variations in air pressure into sound.

Page 15: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

15

How Do Speakers and Microphones Work?

A speaker converts an electrical signal into movement of air, using magnets to push the air back and forth. When it pushes forward, the air is compressed. When it pulls back, the air is rarified, or decompressed.

A microphone does the opposite – it converts the movement of air into an electrical signal.

Page 16: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

16

Digital-to-Analog andAnalog-to-Digital Conversion

Analog-to-digitalConverter

01101001110. .

Digital-to-analogConverter

01101001110. .

Page 17: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

17

Digitization: Turning Sound into 1s and 0sSampling: Converting analog information into a digital representation by measuring the value of the analog signal at regular intervals, and encoding these integer values in digital form – 1s and 0s. Sampling rate (or frequency): How often the measurements are taken.Sampling resolution: How many different values you quantize into. 8 bit resolution allows 256 different values, 16 bit resolution allows 65536 different values. Another way to look at it is, how many marks are there on your ruler? The finer the gradations, the more accurate the representation can be.Quantization error: The difference between the actual signal level and the integer value chosen to represent it

Page 18: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

18

Making Images With Ones and Zeroes

Page 19: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

19

Original Image Divided into pixels Each pixel is averaged

Turning Pictures into Numbers

Page 20: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

20

Turning Pictures into Numbers - 2

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Palette: maps colors to numbers

Page 21: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

21

Digitizing Gone Bad. . .

Original Resolution too low Not enough colorsin palette

Page 22: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

22

A Possible Image File Format• An image file could be constructed like

this:– First, include the palette of colors that are used– Second, give the height and width in pixels– Third, give the pixel data

• More specifically, if the image used 256 different colors:– palette of 256 colors, each color 3 bytes: 768

bytes total– image width in pixels – 2 bytes– image height in pixels – 2 bytes– 1 byte for each pixel – indicates which of the

256 colors goes in that spot

So an image that's 512 x 512 pixels would be:768 + 2 + 2 + 262144 = 262916 bytes total

Page 23: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

23

Run-Length EncodingThere are many ways to compress a bitmapped image. One simple way is run-length encoding, which is effective if an image has a lot of consecutive pixels of the same color. The image is then expressed as a series of pairs, where each pair is a pixel color, and the number of pixels in a row of that color. For the image at left, it could be W, 20, B, 3, W, 1 ,B, 1, W, 11, B, 1, etc.

Page 24: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

24

GIF and JPEG Compression• JPEG (Joint

Photographic Experts Group) better for photos, images with complex color schemes

• GIF (Graphics Interchange Format) better for line art, images with large areas of single color

Page 25: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

25

Medical Imaging – the CAT Scan• The idea behind Computed

Axial Tomography is to take X-rays from many different angles and use the information to construct an image of the object. We are essentially sampling the object with X-rays.

• The elements in a 3D image are called voxels.

Page 26: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

26

A Thought Experiment. . . • Imagine that you had a BB gun that always shot

BBs at the same velocity, and you also had a radar gun that could measure the speed of a BB. . .

• You take some measurements, and discover that different substances slow the BB down by different amounts:

Substance (1 cm thick): BB Slows down by:hamburger 20 m/secjello 15 m/secslurpee 10 m/secwater 5 m/sec

Page 27: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

27

A Thought Experiment (cont)

100 m/sec

100 m/sec

100 m/sec

100 m/sec

Slows down hamburger 20 m/secjello 15 m/secslurpee 10 m/secwater 5 m/sec

70 m/sec

70 m/sec

75 m/sec

65 m/sec

A B

C D

each square is 1 cm2 –Can you determine whatA, B, C, and D are?

Page 28: 1 There are 10 types of people in this world: those that understand binary numbers, and those that dont... Bits and Bytes

28

Computed Axial Tomography

•X-ray tube and detectors revolve around patient•Detectors measure intensity of X-rays after passing through the patient•Computer uses information to reconstruct a 3-D image