Skip to main content
SWStudyWalks Search

Computer Science / Unit 5   CS 0245 worked example, 60 to 90 seconds

One String, Four Readings

Captions available

The idea

A single bit string decodes to different values under different declared types — and running one string through four readings proves the type, not the bits, carries the meaning.

In practice

Take the three bits 101. Reading one, unsigned: positions score 1 times four, 0 times two, 1 times one — the value 5. Reading two, sign-magnitude: the leading 1 means negative, the remaining 01 means one — the value negative 1. Reading three, one's complement: the leading 1 says negative and flip to decode; flipping 101 gives 010, which is 2 — the value negative 2. Reading four, two's complement: negative again, and decoding takes the one's complement plus one; 010 plus 1 is 011, which is 3 — the value negative 3. Four declared types, four honest answers from the same three bits: 5, negative 1, negative 2, negative 3. Nothing about the string changed. The reading rules did all the deciding, which is exactly what video 0238 claimed.

Where people slip

A decoded value with no stated type attached is an answer to an unasked question.

Your place on the trail

Every lesson rests on earlier ones and opens later ones. Tap any to jump.

Unlocks

  • Nothing yet depends on this.

Something wrong in this lesson? Flag it  ·  Sources for Computer Science