TAOCP Vol 2: Seminumerical Algorithms · Week 74

TAOCP 4.1 Positional Number Systems

Updated

About 5 hours34 exercises, rated 00 to M40

Summary

TAOCP 4.1 Positional Number Systems: Number representations: binary, octal, hex, and exotic systems like negative bases, balanced ternary, and mixed radix. Budget about 5 hours; do exercises 1, 9 and 2.

Knuth also covers a little history of how positional notation developed.

Flashcards 14 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §4.1 Positional Number Systems

    Convert a few numbers to base -2 and balanced ternary by hand.

  2. Work the exercises (8 picked)

    Start with Ex 1, Ex 9, Ex 2; log what you solve below.

  3. Write down one thing you'd explain to someone

    A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

Sign in to track this: tick each step off and it counts toward your week.

Exercises

This section has 34 exercises, rated 00 to M40, and Knuth marks 8 of them with the triangle for recommended. Do the conversion drills quickly and then implement negabinary addition and the minimal signed-digit form; those are the exercises that pay back in code.

Worth your time

  • Exercise 115

    Write small integers in base -2. Drill.

    Discuss

  • Exercise 224▶ Recommended

    Express a few numbers in four unusual systems. Shows the tradeoffs side by side.

    Discuss

  • Exercise 915▶ Recommended

    Octal to hexadecimal by regrouping bits.

    Discuss

  • Exercise 1122

    Design negabinary addition.

    Discuss

  • Exercise 13M21▶ Recommended

    Whether expansions in base -10 can be ambiguous, like 0.999... in decimal.

    Discuss

  • Exercise 1923▶ Recommended

    Which digit sets let every integer be written in a given base.

    Discuss

  • Exercise 31M35▶ Recommended

    2-adic numbers as infinite two's complement. The stretch.

    Discuss

  • Exercise 3422▶ Recommended

    Write an integer with digits -1, 0, 1 using the fewest nonzero digits. Used in fast exponentiation and hardware multipliers.

    Discuss

Your log

Sign in to log the exercises you work: number, rating, how far you got.

Your notes

Only you

Sign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.

Discussion

0 posts

Questions about the reading go here; each exercise has its own thread below. Hints over answers.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Exercise threads

One thread per exercise. Open one to ask for a nudge or check your thinking.

  • Exercise 115No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 224No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 915No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1122No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 13M21No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1923No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 31M35No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 3422No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

Why it matters

Bit manipulation, encodings and serialization formats all depend on fluent radix thinking. Mixed radix is how you convert time units and index multi-dimensional arrays.

Before you start
  • 1.2.4 Integer Functions
How to approach it

Convert a few numbers to base -2 and balanced ternary by hand. Write a function that converts to any mixed radix.

Common traps
  • Rushing through the negative-base examples. They are fun and they check your understanding.

Spot a mistake? Report it

Back to week 74