Problem 1: Which byte is the letter?
Bits, bytes and ASCII · Related: Lecture 4
The problem
An exam question shows four bytes, 01000111, 01001010, 01000101 and 01001001, and asks which one stands for the capital letter J. You know that A is 65 in ASCII and the capitals follow in alphabetical order.
Method
- Find the decimal value of the target character: count from A = 65.
- Convert each byte: add the position values 128, 64, 32, 16, 8, 4, 2, 1 where the bit is 1.
- Compare; check the answer by converting it back.
Find J
J is the tenth letter, so J = 65 + 9 = 74.
01000111
01001010
01000101
01001001
The answer is 01001010. Small letters start at 97 (a), so j would be 106 = 01101010: only the bit worth 32 differs.
Think further
- Every capital letter starts with 010 (64 + a number up to 26).
- The bit worth 32 switches between capital and small letter.
- A byte holds 0 to 255, so 8 bits are enough for all ASCII characters.
Practice question
Which character is 01010011? And what is the byte of the digit 7, knowing that the digit 0 is 48 in ASCII?
Show the answer
- 64 + 16 + 2 + 1 = 83 = S.
- Digit 7 = 48 + 7 = 55 = 32 + 16 + 4 + 2 + 1 = 00110111.