taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.3.1-2

Exercise 1.3.1-2

not stated yet in Lean solution written

Rating02
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 1.3.1 of Volume 1. Companion chapter: Description of MIX

The task

Find the number of adjacent bytes that always suffice to hold an integer up to 9999999999999999.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

The size of a byte is not fixed. Use the smallest legal byte size, b=64b = 64.

Hint 2

Compare b4b^4 and b5b^5 with 10810^8.

Solution

Show the solution

The program must be right for every byte size from 6464 to 100100. With b=64b = 64 the value of four bytes is at most 644−1=1677721564^4 - 1 = 16777215, which is less than 9999999999999999. So four bytes are not enough. Five bytes hold up to 645−1=107374182364^5 - 1 = 1073741823, which is more than 9999999999999999, and this is true for every larger bb. The answer is five bytes.

Check

python3: 64**4 = 16777216 < 10**8 <= 64**5 = 1073741824. For b=100b = 100 the number 1004=108100^4 = 10^8 would suffice, but that is not allowed as an assumption.

Remarks

The same reasoning shows why a 10-digit decimal word is the safe size for the whole word: the sign and five bytes, with the value at most b5−1b^5 - 1.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.