Docsity

Understanding Information Representation: Binary, Hexadecimal, and ASCII, Study notes of Computer Science

Partial preview of the text

Download Understanding Information Representation: Binary, Hexadecimal, and ASCII and more Study notes Computer Science in PDF only on Docsity!

REPRESENTING INFORMATION:

BINARY, HEX, ASCII

CORRESPONDING READING:

UDC CHAPTER 2

CMSC 150: Lecture 2

Controlling Information

Watch Newman on YouTube

Inside the Computer: Gates

AND Gate Input Wires Output Wire

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

Inside the Computer: Gates

Example: your favorite number…

8,675,

The Binary Number System

! Bi- (two)

 bicycle, bicentennial, biphenyl

! Base two

 first (rightmost) place: ones (i.e., 2^0 )

 second place: twos (i.e., 2^1 )

 third place: fours (i.e., 2^2 )

! Digits available: 0, 1 (two total)

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

" filling to the right with 0's as necessary

Example

! 8,675,309 10

(^1000010001011111111011012) ! Fewer available digits in binary: more space required for representation

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

Too Much Information?

Too Much Information?

Too Much Information?

An Alternative to Binary?

! What if this was km to landing?

The Hexadecimal Number System

! Hex- (six) Deci- (ten) ! Base sixteen  first (rightmost) place: ones (i.e., 16^0 )  second place: sixteens (i.e., 16^1 )  third place: two-hundred-fifty-sixes (i.e., 16^2 )  … ! Digits available: sixteen total 0, 1, 2, …, 9, A, B, C, D, E, F

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

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?

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 2^4 = 16 different values

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

Converting Binary to Hex

! Moving right to left, group into bits of four ! Convert each four-group to corresponding hex digit ! (^1000010001011111111011012)

Converting Hex to Binary

! Simply convert each hex digit to four-bit binary equivalent ! BEEF 16 = 1011 1110 1110 1111 2

ASCII: American Standard Code for Information Interchange

ASCII: American Standard Code for Information Interchange

'A' = 65 10 = ??? 2 'q' = 90 10 = ??? 2 '8' = 56 10 = ??? 2

ASCII: American Standard Code for Information Interchange

256 total characters… How many bits needed?

The Problem with ASCII

! What about Greek characters? Chinese? ! UNICODE: use 16 bits ! How many characters can we represent?

You Control The Information

! What is this? 01001101 ! Depends on how you interpret it: ! 010011012 = 77 10 ! 010011012 = 'M' ! 0100110110 = one million one thousand one hundred and one ! You must be clear on representation and interpretation