representing information - university of richmonddszajda/classes/... · representing decimal in...

38
REPRESENTING INFORMATION: BINARY, HEX, ASCII CORRESPONDING READING: WELL, NONE IN YOUR TEXT. SO LISTEN CAREFULLY IN LECTURE (BECAUSE IT WILL BE ON THE EXAM(S))! CMSC 150: Fall 2015

Upload: others

Post on 03-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

REPRESENTING INFORMATION: BINARY, HEX, ASCII

CORRESPONDING READING:

WELL, NONE IN YOUR TEXT. SO LISTEN CAREFULLY IN LECTURE (BECAUSE IT WILL BE

ON THE EXAM(S))!

CMSC 150: Fall 2015

Page 2: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Controlling Information

Watch Newman on YouTube

Page 3: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Inside the Computer: Gates

AND Gate

Input Wires

Output Wire

0

1

0

0's & 1's represent low & high voltage, respectively, on the wires

Page 4: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Inside the Computer: Gates

Page 5: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Representing Information

¨ We need to understand how the 0's and 1's can be used to "control information"

Page 6: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

The Decimal Number System

¨ Deci- (ten)

¨ Base is ten ¤ first (rightmost) place: ones (i.e., 100) ¤ second place: tens (i.e., 101) ¤ third place: hundreds (i.e., 102) ¤ …

¨ Digits available: 0, 1, 2, …, 9 (ten total)

Page 7: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Example: your favorite number…

8,675,309

Page 8: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

The Binary Number System

¨ Bi- (two) ¤ bicycle, bicentennial, biphenyl

¨ Base two ¤ first (rightmost) place: ones (i.e., 20) ¤ second place: twos (i.e., 21) ¤ third place: fours (i.e., 22) ¤ …

¨ Digits available: 0, 1 (two total ¨ Phrase “binary digit” shortened to “bit”

Page 9: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Quantity of Bits (Memory)

¨ 1 Byte (1B) = 8 bits ¨ 1 Kilobyte (1KB) = 210 = 1024 bytes ¨ 1 Megabyte (1MB) = 220 ~ 1,000,000 bytes ¨ 1 Gigabyte (1GB) = 230 ~ 1,000,000,000 bytes ¨ 1 Terabyte (1TB) = 240 ~ 1,000,000,000,000 bytes

¨ These last four have beens standardized of late for powers of 10, rather than 2 (e.g., 103, 106, 109, 1012)

9

Page 10: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Representing Decimal in Binary

¨ Moving right to left, include a "slot" for every power of two <= your decimal number

¨ Moving left to right: ¤ Put 1 in the slot if that power of two can be subtracted

from your total remaining ¤ Put 0 in the slot if not ¤ Continue until all slots are filled

n filling to the right with 0's as necessary

Page 11: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Example

¨ 8,675,30910

=

1000010001011111111011012

¨ Fewer available digits in binary: more space required for representation

Page 12: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Converting Binary to Decimal

¨ For each 1, add the corresponding power of two

¨ 10100101111012

Page 13: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Converting Binary to Decimal

¨ For each 1, add the corresponding power of two

¨ 10100101111012 = 530910

Page 14: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Now You Get The Joke

THERE ARE 10 TYPES OF PEOPLE IN THE WORLD:

THOSE WHO CAN COUNT IN BINARY

AND THOSE WHO CAN'T

Page 15: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Too Much Information?

Page 16: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Too Much Information?

Page 17: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Too Much Information?

Page 18: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

An Alternative to Binary?

¨ 1000010001011111111011012 = 8,675,30910

¨ 1000001001011111111011012 = 8,544,23710

Page 19: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

An Alternative to Binary?

¨ 1000010001011111111011012 = 8,675,30910

¨ 1000001001011111111011012 = 8,544,23710

Page 20: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

An Alternative to Binary?

¨ What if this was km to landing?

Page 21: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

The Hexadecimal Number System

¨ Hex- (six) Deci- (ten) ¨ Base sixteen

¤ first (rightmost) place: ones (i.e., 160) ¤ second place: sixteens (i.e., 161) ¤ third place: two-hundred-fifty-sixes (i.e., 162) ¤ …

¨ Digits available: sixteen total 0, 1, 2, …, 9, A, B, C, D, E, F

Page 22: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Using Hex

¨ Can convert decimal to hex and vice-versa ¤ process is similar, but using base 16 and 0-9, A-F

¨ Most commonly used as a shorthand for binary

¨ Avoid this

Page 23: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

More About Binary

¨ How many different things can you represent using binary:

¨ with only one slot (i.e., one bit)? ¨ with two slots (i.e., two bits)? ¨ with three bits? ¨ with n bits?

Page 24: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

More About Binary

¨ How many different things can you represent using binary:

¨ with only one slot (i.e., one bit)? 2 ¨ with two slots (i.e., two bits)? 22 = 4 ¨ with three bits? 23 = 8 ¨ with n bits? 2n

Page 25: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Binary vs. Hex

¨ One slot in hex can be one of 16 values 0, 1, 2, …, 9, A, B, C, D, E, F

¨ How many bits do you need to represent one hex digit?

Page 26: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Binary vs. Hex

¨ One slot in hex can be one of 16 values 0, 1, 2, …, 9, A, B, C, D, E, F

¨ How many bits do you need to represent one hex digit?

¨ 4 bits can represent 24 = 16 different values

Page 27: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Binary vs. Hex

0 0000

1 0001

2 0010

3 0011

4 0100

5 0101

6 0110

7 0111

8 1000

9 1001

A 1010

B 1011

C 1100

D 1101

E 1110

F 1111

Page 28: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Converting Binary to Hex

¨ Moving right to left, group into bits of four ¨ Convert each four-group to corresponding hex digit

¨ 1000010001011111111011012

Page 29: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Converting Hex to Binary

¨ Simply convert each hex digit to four-bit binary equivalent

¨ BEEF16 = 1011 1110 1110 11112

Page 30: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Representing Different Information

¨ So far, everything has been a number

¨ What about characters? Punctuation?

¨ Idea: ¤ put all the characters, punctuation in order ¤ assign a unique number to each ¤ done! (we know how to represent numbers)

Page 31: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

Our Idea

¨ A: 0 ¨ B: 1 ¨ C: 2 ¨ … ¨ Z: 25 ¨ a: 26 ¨ b: 27 ¨ … ¨ z: 51

¨ , : 52

¨ . : 53

¨ [space] : 54

¨ …

Page 32: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

ASCII: American Standard Code for Information Interchange

Page 33: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

ASCII: American Standard Code for Information Interchange

'A' = 6510 = ???2

'q' = 9010 = ???2

'8' = 5610 = ???2

Page 34: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

ASCII: American Standard Code for Information Interchange

256 total characters…

How many bits needed?

Page 35: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

The Problem with ASCII

¨ What about Greek characters? Chinese?

¨ UNICODE: use 16 bits

¨ How many characters can we represent?

Page 36: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

The Problem with ASCII

¨ What about Greek characters? Chinese?

¨ UNICODE: use 16 bits

¨ How many characters can we represent?

¨ 216 = 65,536

Page 37: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

You Control The Information

¨ What is this? 01001101

Page 38: REPRESENTING INFORMATION - University of Richmonddszajda/classes/... · Representing Decimal in Binary! Moving right to left, include a "slot" for every power of two

You Control The Information

¨ What is this? 01001101

¨ Depends on how you interpret it:

¨ 010011012 = 7710 ¨ 010011012 = 'M' ¨ 0100110110 = one million one thousand one hundred

and one

¨ You must be clear on representation and interpretation