← Binary Course — Part E, lesson 2 of 4 (Reading real machine words)
19. Worked Example: Decoding a Raw Word From the LGP-30
The concept
Lesson 18 named the theme; this lesson applies it, once, to an actual machine's actual word — not the abstract 8-bit teaching pattern every earlier lesson used, but a real 32-bit word from the LGP-30, a real 1956 drum computer, using its documented conventions exactly as written up in its own 1957 programming manual. Since this word is wider than every example so far, its width is stated explicitly, every time, rather than assumed: every value below is a 32-bit word.
The LGP-30's word format lays out three pieces, each of which needs an externally-stated convention to mean anything — exactly Lesson 18's point, just with real bit positions attached:
- Bit 31 (leftmost): the sign bit.
0for positive,1for negative — the same leftmost-bit convention this course has used since Lesson 9, just at a much wider width. - Bits 30 down to 1: the magnitude, always read as a binary
fraction between 0 and just under 1, with the point implied right
after the sign bit. This machine has no separate "whole number word"
format at all — every magnitude, always, is Lesson 14's fractional
place value, nothing else. On its own that fraction is stuck between 0
and 1; turning it into a real-world value like
6needs a scale factor, writtenq, chosen by the programmer and never stored anywhere in the word — exactly Lesson 16's "the point never appears inside the stored bits; it only exists in the program's bookkeeping," restated here as an actual documented feature of a real machine rather than this course's own invented convention. The relationship is: true value = magnitude fraction × 2^q. - Bit 0 (rightmost): a spacer, always
0on the drum. Unlike the other 31 bits, it isn't a fraction position at all — it's excluded from the numeric reading entirely, for a physical/timing reason inside the hardware that has nothing to do with representing a value. Example 3 below returns to why that's worth pausing on.
One more real wrinkle is worth stating plainly before the examples, because it's the sharpest possible demonstration of a point Part C only made in the abstract. This machine is usually described as "sign-magnitude," since it stores exactly one sign bit alongside a magnitude. But its negative numbers are not sign-magnitude in the sense Lesson 9 defined — flipping only the sign bit and leaving the magnitude untouched, the way Lesson 9's Example 1 worked, is not how this machine builds a negative value. Its actual, documented rule is Lesson 11's two's complement — invert every bit, then add 1 — applied to the entire 31-bit sign-and-magnitude field together, sign bit included, not to a separate magnitude alone. A real machine's negative numbers turn out to need Lesson 11's method, applied somewhere Lesson 9's simpler picture would have predicted Lesson 9's own naive (and already-flagged-wrong) shortcut instead.
Example 1 — Decoding a positive word
The 1957 manual's own example: the value 6, at scale factor q = 4.
6 / 2^4 = 0.375, and 0.375 in binary (Lesson 15's doubling method,
or read directly) is 0.011. Sign 0, magnitude 011 followed by 27
more zero bits to fill out all 30 magnitude positions, spacer 0:
0011 0000 0000 0000 0000 0000 0000 0000
Reading it back: sign bit 0 (positive). Magnitude bits, read as a
fraction (Lesson 14): 0.011000...0 = 0.375. Apply the stated scale
factor: 0.375 x 2^4 = 6. The word decodes to 6 — but only once q = 4 is known; nothing inside those 32 bits states it.
Example 2 — Decoding a negative word, and the naive guess that fails
Negate 6 at the same scale, q = 4. The tempting guess, straight from
Lesson 9's sign-magnitude habit, is to take Example 1's word and flip
only the sign bit:
naive (wrong) guess: 1011 0000 0000 0000 0000 0000 0000 0000
That is not the word this machine actually stores. The manual's own
documented value for -6 at q = 4 is:
1101 0000 0000 0000 0000 0000 0000 0000
Decoding it needs Lesson 11's real method, applied to the whole 31-bit sign+magnitude field (everything except the spacer): invert every one of those 31 bits, then add 1, to recover the positive field it came from.
field (31 bits): 1101000...0
invert: 0010111...1
add 1: 0011000...0 <- the sign+magnitude field of +6
That recovered field is exactly Example 1's +6 field: sign 0,
magnitude 0.375. So the original word represents the negation of
that: -(0.375 x 2^4) = -6 — correct, but only by running Lesson 11's
invert-then-add-1 procedure, not by reading the stored magnitude bits at
face value and slapping on a minus sign. Doing that instead — reading
1101 0000...'s own magnitude bits directly as 0.101 = 0.625 and
calling the answer -(0.625 x 16) = -10 — is exactly the sign-magnitude
misreading Lesson 9 taught, applied to a machine that doesn't use that
scheme for its negative numbers. Getting this word's real value right
requires already knowing which of Part C's three schemes actually
applies here — precisely Lesson 18's point, now with real stakes: guess
wrong, and the answer isn't just imprecise, it's a completely different
number.
Example 3 — The spacer bit: excluded, not just zero
Every word in Examples 1-2 ends in 0 — the spacer, bit 0. It's
tempting to think of it as simply "the fraction's very last position,
which happens to be zero in both these examples." That reading is
wrong, and no amount of staring at example words can prove it wrong:
every real word on this drum has that bit at 0, always, so a
zero-valued last fraction position and a categorically-excluded
non-numeric position look identical in every worked example this
lesson could ever show. The two claims only come apart in the manual's
own stated purpose for that bit — physical drum-timing behavior during
character input, unrelated to representing a value at all — which is
information no bit pattern could ever supply about itself. This is
Lesson 18's theme at its most literal: not just "which convention
applies," but "which bits are even part of the value in the first
place," is exactly as external a decision as everything else in this
lesson, and here it happens to be a fact no dataset could ever reveal on
its own.
Exercises
Exercise 1. Decode the 32-bit word 0110 0000 0000 0000 0000 0000 0000 0000, given a stated scale factor of q = 2, using Example 1's
method.
Exercise 2. The value -3 at q = 2 is stored, on this machine, as
the 32-bit word 1010 0000 0000 0000 0000 0000 0000 0000. Decode it
using Example 2's method (invert the 31-bit sign+magnitude field, add
1, then read the recovered magnitude as a fraction and apply q).
Exercise 3. A classmate wants to store -5 at q = 3. They take
the word for +5 at q = 3 (0101 0000 0000 0000 0000 0000 0000 0000) and flip only its sign bit, producing 1101 0000 0000 0000 0000 0000 0000 0000. Using Example 2's real decoding method, what value
does their word actually represent? What should the correct word for
-5 at q = 3 be instead, and how is it built?
Show Answer Key
1. Sign 0 (positive). Magnitude 0.11000...0 = 0.75. Value at
q = 2: 0.75 x 2^2 = 3.
2. Field (31 bits): 1010000...0. Invert: 0101111...1. Add 1:
0110000...0 — the sign+magnitude field of +3 at this scale (sign
0, magnitude 0.11 = 0.75). So the original word represents
-(0.75 x 2^2) = -3.
3. Decoding the classmate's word with Example 2's real method:
field 1101000...0, invert (0010111...1), add 1 (0011000...0) —
the recovered field for sign 0, magnitude 0.011 = 0.375. So their
word actually represents -(0.375 x 2^3) = -3, not -5 — wrong, and
not narrowly wrong, the same way Lesson 11 Exercise 3's sign-flip
mistake decoded to -116 instead of -12. Flipping only the sign bit
is not this machine's negation rule. The correct word for -5 at
q = 3 is built the way Example 2 built -6: take +5's full 31-bit
sign+magnitude field (0101000...0), invert it (1010111...1), add 1
(1011000...0), then append the spacer bit: 1011 0000 0000 0000 0000 0000 0000 0000.
Every reading in this lesson — the sign bit, the fractional magnitude, the scale factor, and the real two's-complement negation rule — reused machinery this course already built; nothing here was new mechanics, only a real word to point it at. Lesson 20 turns to practice: a set of raw dumps with mixed, sometimes-ambiguous readings, decoded with no worked example alongside to lean on.
Sign in to mark lessons complete and keep your progress.