Lecture 7   Class Activities for Information Representation

Look forward to hearing from your advisor to make an appointment early next week to discuss a draft of your requirements document.

Computer Organization

Computers have changed a lot in the hardware details over the decades, yet they are still using a fundamental architecture that hasn't changed very much at all.

Quiz Question Nr 1.

Which of the following is not part of a computer:

  1. ALU

  2. CPU

  3. BLU

  4. bus

  5. RAM

  6. clock

Quiz Question Nr 2.

The clock does the following:

  1. Determines the speed of the processor

  2. Determines the speed of the memory

  3. Sets the timestamp for files and network I/O

  4. Synchronizes with GPS satellites

  5. all of the above

Binary Numbers

It may be surprising, but we can create any number we want out of just two digits, zero and one. These two binary digits are called bits.

Powers of Two

Essential to creating binary numbers is knowing your powers of two. You'll soon be able to create the following table quickly and reliably:

01
12
24
38
416
532
664
7128
8256
k2k
log2(n)n

Quiz Question Nr 3.

The binary equivalent of 5 is

  1. 5

  2. 10000

  3. 110

  4. 101

Quiz Question Nr 4.

The decimal equivalent of the binary number 1010 is

  1. 6

  2. 5

  3. 12

  4. none of the above

Let's also try some of the following numbers:

  • 20
  • 127
  • 255
  • 67
  • 115
  • 49

There are some interesting observations to make about those numbers:

  • What happens when a number is multiplied by two or a power of two?
  • What does a number look like when it is a power of two?
  • What does a number look like when it is near a power of two?

Characters, ASCII and Unicode

Once we have numbers, we can represent characters and text by simply numbering the characters.

  • Typically, each character is represented in a fixed width (1 byte or 2 bytes) or a small variety of widths. This may require leading zeros
  • ASCII is very old, extremely well-supported, and limited to 256 characters
  • Unicode is relatively modern (though decades old), still dodgy in its support, and has few practical limits (billions of characters).
  • There are other odd issues to deal with, such as encoding of line-endings.

Quiz Question Nr 5.

What is 67 expressed as ASCII?

  1. A

  2. B

  3. C

  4. none of the above

What are 115 and 49 expressed as ASCII?

Limited Number Representations

The fact that ASCII uses a limited number of bits has important implications. It can't represent an unbounded number of characters. This is true of all representations that use a limited number of bits.

  • Did you hear about how Psy broke YouTube's view counter?. That's because YouTube used a fixed-size counter.
  • Did you hear that we are running out of IP addresses

Color Representation

Because of the way human vision works, we can represent pretty much any color using three primaries:

  • Red
  • Green
  • Blue

If we represent the amount of each with a number from 0-255.

  • Why 255?
  • How many colors can we have?

Hexadecimal

Programmers use hex to have a convenient replacement for binary, because strings of bits are hard to read and hard to write. We will see that there is an easy way to convert binary to hex and vice versa. But first, we'll learn about hex as a number system, where is also finds use in programming.

Hex Numbers

In hex,

  • Digits can be 0-F (0-15 in base 10).
  • Each digit is the equivalent of a four-bit number
  • The place values are powers of sixteen

First, we'll count in hex up to 29.

Quiz Question Nr 6.

The hex equivalent of 3710 is

  1. 37

  2. 45

  3. 47

  4. none of the above

Quiz Question Nr 7.

The hex equivalent of 9010 is

  1. 50

  2. 90

  3. 5A

  4. none of the above

Quiz Question Nr 8.

The decimal equivalent of BA16 is

  1. 186

  2. 180

  3. 190

  4. none of the above

Hex and Colors

There's a nice match between colors being represented as 3 bytes and hex digits:

  • Every six-digit hex string can be interpreted as a color and
  • every color can be written as a six-digit hex string.

Quiz Question Nr 9.

Earlier, we saw the numbers 67, 115, and 49 converted to ASCII. Converted to a color, they are:

  1. #437331

  2. #438331

  3. #437349

  4. none of the above

Quiz Question Nr 10.

What does that color look like?

  1. light red

  2. dark green

  3. light blue

  4. none of the above

Colors and Image

Colors can be represented as rectangular collections of spots of color called pixels. An image file comes in a variety of formats, some of which are uncompressed and some are compressed.

We will study the ideas behind one particular compressed format, namely GIF and touch on the others.

Quiz Question Nr 11.

What is the approximate image size in bytes of an uncompressed image of 200 x 300 with 30 colors in it?

  1. 200 x 300 x 30

  2. 200 x 300 x 3

  3. (200 x 300 x 3)/8

  4. (200 x 300 x 30)/8

  5. 200 x 300 x 4

  6. (200 x 300 x 4)/8

Indexed Color

Indexed color depends crucially on the bit-depth, which is just another form of the relationship between the number of bits devoted to a representation and the number of different things you can represent.

Quiz Question Nr 12.

What is the bit-depth of an image with 30 colors in it?

  1. 30

  2. 3

  3. 4

  4. 5

Quiz Question Nr 13.

What is the approximate image size in bytes of an image of 200 x 300 with 30 colors in it, using indexed-color representation?

  1. 200 x 300 x 30

  2. 200 x 300 x 3

  3. (200 x 300 x 3)/8 + 30 x 3

  4. (200 x 300 x 30)/8

  5. (200 x 300 x 5)/8 + 30 x 3

  6. none of the above

Quiz Question Nr 14.

What is the best image file format?

  1. GIF

  2. JPEG

  3. PNG

  4. none of the above

Solutions

  1. C. BLU is not part of the computer.
  2. A. The clock determines the speed of the processor
  3. D. The binary equivalent of 5 is 101
  4. D. The decimal equivalent of 1010 is 10.
  5. C. The ASCII charactaer 67 is "C"
  6. D. The hex equivalent of 3710 is 2516
  7. C. The hex equivalent of 9010 is 5A16
  8. A. The decimal equivalent of BA16 is 18610
  9. D. The color 67, 115, 49 is #437331
  10. B. The color is a dark green
  11. B. The approx size is 200 x 300 x 3 bytes.
  12. D. The bit depth for 30 colors is 5
  13. E. The approx size is (200 x 300 x 5)/8 + 30 x 3 bytes.
  14. D. There is no best image file format.