# Review R: Representing data

*printable version*

**R1:**
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
**// R2:**
[1]
[2]
[3]
[4]
**// R3:**
[1]
[2]
[3]
[4]

### Problem R1.1

How many bits are in a kilobyte of memory?

There are 8,192 bits in a kilobyte:

8 bits × 1,024 bytes = 8,192 bits byte KB KB

### Problem R1.2

Approximate 2^{34} in the form `x` × 10^{y}, with
`x` and `y` both being base-10 integers. (Your
answer need not be normalized.)

16 × 10^{9}

### Problem R1.3

Approximate 2^{45} in the form `x` × 10^{y},
with `x` and `y` both being base-10 integers. (Your answer
need not be normalized.)

32 × 10^{12}

### Problem R1.4

Approximately how many kilobytes are accessible with a 23-bit address space?

8,000.
(2^{23} / 2^{10} = 2^{13} = 2^{3} × 2^{10} ≈ 8 × 10^{3} = 8,000.
We divide initially by 2^{10} because that is how many
bytes are in a kilobyte.)

### Problem R1.5

Perform each of the following conversions.

a. | 101101_{(2)} | to decimal |

b. | 1010101_{(2)} | to decimal |

c. | 23_{(10)} | to binary |

d. | 95_{(10)} | to binary |

a. | 101101_{(2)} | = 45_{(10)} |

b. | 1010101_{(2)} | = 85_{(10)} |

c. | 23_{(10)} | = 10111_{(2)} |

d. | 95_{(10)} | = 1011111_{(2)} |

### Problem R1.6

Given that humans almost always use base-10 numbers,
while modern computers *always* work with base-2 numbers,
why do programmers often choose to write numbers in base 16?

Humans communicate much more easily with short strings, and hexadecimal numbers are 4 times shorter than binary numbers, so that is why they prefer hexadecimal over binary. However, we sometimes want to avoid decimal, since decimal numbers cannot be easily converted to binary representation, and often the binary representation is crucial to a program's meaning; by contrast, hexadecimal has a straightforward correspondence to binary.

### Problem R1.7

Perform each of the following conversions. Show your work.

a. |
110110_{(2)} | to decimal |

b. |
140_{(10)} | to binary |

c. |
E1EC7ED_{(16)} | to binary |

a. |
110110_{(2)} | = | 54_{(10)} |

b. |
140_{(10)} | = | 10001100 |

c. |
E1EC7ED_{(16)} | = | 1110 0001 1110 1100 0111 1110 1101_{(2)} |

### Problem R1.8

Perform each of the following conversions.

a. | 1010101010101_{(2)} | to octal |

b. | 10101010101010_{(2)} | to hexadecimal |

c. | 101101_{(2)} | to hexadecimal |

d. | 560_{(8)} | to binary |

e. | CAB_{(16)} | to binary |

f. | D15EA5ED_{(16)} | to binary |

a. | 1 010 101 010 101_{(2)} |
= 12525_{(8)} |

b. | 10 1010 1010 1010_{(2)} |
= 2AAA_{(16)} |

c. | 10 1101_{(2)} |
= 2D_{(16)} |

d. | 560_{(8)} |
= 101 110 000_{(2)} |

e. | CAB_{(16)} |
= 1100 1010 1011_{(2)} |

f. | D15EA5ED_{(16)} |
= 1101 0001 0101 1110 1010 0101 1110 1101_{(2)} |

### Problem R2.1

Represent each of the following using the 8-bit two's-complement integer representation.

a. | 10_{(10)} |

b. | −60_{(10)} |

c. | −104_{(10)} |

a. | 10_{(10)} |
→ | 0000 1010 |

b. | −60_{(10)} |
→ | 1100 0100 |

c. | −104_{(10)} |
→ | 1001 1000 |

### Problem R2.2

Represent each of the following in a two's-complement representation.

a. | −1_{(10)} |
in a seven-bit two's-complement format |

b. | −20_{(10)} |
in a seven-bit two's-complement format |

c. | 20_{(10)} |
in a seven-bit two's-complement format |

d. | −300_{(10)} |
in twelve-bit two's-complement format |

a. | −1_{(10)} |
→ | 111 1111 |

b. | −20_{(10)} |
→ | 110 1100 |

c. | 20_{(10)} |
→ | 001 0100 |

d. | −300_{(10)} |
→ | 1110 1101 0100 |

### Problem R2.3

For the following, assume a six-bit two's-complement representation of integers.

a. | What numeric value does 110110 represent? |

b. | What numeric value does 010101 represent? |

c. | What bit pattern is used to represent
−12_{(10)}? |

a. | 110110 | → | −10_{(10)} |

b. | 010101 | → | 21_{(10)} |

c. | −12_{(10)} | → | 110100 |

### Problem R2.4

**a.** What is the smallest (most negative) number you can represent in
seven bits using sign-magnitude representation?
Give both the bit pattern of the number and its base-10
translation.

**b.** Answer the same question for a seven-bit two's-complement
representation.

a. | Sign-magnitude: | 111 1111 represents −63_{(10)} |

b. | Two's-complement: | 100 0000 represents −64_{(10)} |

### Problem R3.1

Explain what ASCII is.

ASCII is a mapping to seven-bit values for the characters found on an English keyboard and special symbols.

### Problem R3.2

In addition to characters, digits, punctuation symbols, and the space character, ASCII also includes some “unprintable” special symbols. Describe three of these special symbols.

- The LF (linefeed) character is used to represent line breaks in a file. It is sometimes accompanied by a preceding CR (carriage return) character.
- NUL (ASCII 0) is used by C to represent the end of a string.
- BS represents a typed backspace
- ESC represents a typed escape key
- HT represents a tab character
- BEL represents a sounded bell
- FF represents a command to eject a page (or clear the screen)

### Problem R3.3

Identify three categories of characters that are defined in Unicode but not in ASCII.

There are many answers here, but some possibilities:
accented characters for other European languages (like
*ñ*, *é*, and *ö*),
Chinese characters (Han alphabet),
the Cherokee alphabet, the Greek alphabet,
the Arabic alphabet, the Hebrew alphabet, Egyptian hieroglyphics,
playing cards, emoticons, mathematical symbols,
musical notes and symbols.

### Problem R3.4

Distinguish the UTF-8 and UTF-16 encodings for Unicode.

Both represent ways to encode Unicode code points into binary representation. UTF-16 works in two-byte blocks with all code points up to U+FFFF being encoded in precisely two bytes, But UTF-8 works in one-byte blocks with code points up to U+FFFF being encoded in one to three bytes; this allows UTF-8 to be backwards compatible with files represented simply with one ASCII character per byte.