Long before ASCII, teleprinters spoke in five bits. This encoder turns ordinary text into ITA2 Baudot codes, handling the letters-versus-figures shifting that made a 32-code alphabet cover far more than 32 characters.
How it works
ITA2 assigns each printable character a 5-bit code. With only 32 codes available, the same bit pattern means two different things depending on the current mode. Two reserved codes switch modes:
LTRS = 11111 (switch to letters)
FIGS = 11011 (switch to figures and punctuation)
The encoder tracks the current mode. When the next character lives in the other mode, it first emits the appropriate shift marker, then the character’s code. Space, carriage return and line feed share one code across both modes, so they never force a shift.
Tips and notes
- Lowercase input is folded to uppercase, since ITA2 has no lowercase.
- The shift markers add to the code count whenever you alternate between letters and digits, which is why mixed text expands more than its character count.
- Characters outside the ITA2 repertoire are listed as skipped rather than silently mis-encoded.