DEC TO BIN

Developer(s): Stan Livingston
Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Utility

DEC TO BIN converts a decimal number (0–255) to its binary representation by exploiting the TS2068’s pixel-mapped display. The program POKEs the input value into memory address 65376, which causes the system to render the corresponding 8-bit binary pattern as lit or unlit pixels in a single screen row. It then reads each pixel back with POINT, printing a 1 or 0 for each of the 8 bit positions. The loop runs from pixel column 0 to 7 at row 175, reconstructing the binary digits directly from the display hardware. After showing the result, PAUSE 0 waits for a keypress before clearing the screen and looping for a new input.


Program Structure

The program is compact at just eight active lines. Execution flows linearly from input through display, readback, and output, then loops back via GO TO 10. A SAVE statement at line 9998 stores the program with auto-run from line 1.

Line(s)Purpose
2REM — author/title comment
5REM — internal program name tag
10INPUT decimal value into variable l
20POKE value into display memory address 65376
30Print “BIN” label using UDG characters
40–60FOR loop reads 8 pixels with POINT, printing each bit
70Print the original decimal value as confirmation
80Wait for keypress, clear screen, restart

Core Technique: Display Memory as a Binary Decoder

The central trick is using the pixel display as an 8-bit register. Address 65376 corresponds to a specific byte in the display file. When a value is POKEd there, the hardware stores it as eight pixels — one per bit — either lit (1) or unlit (0). The program then uses POINT (m, 175) in the loop (m from 0 to 7) to read back each pixel as a 1 or 0, effectively performing the decimal-to-binary conversion via hardware rather than arithmetic.

POINT-Based Bit Extraction

POINT returns 1 if the addressed pixel is set and 0 if it is clear, making it a natural single-bit readout. By iterating across the eight horizontal pixel positions at the fixed row 175, the loop prints the binary digits in order from MSB (bit 7) to LSB (bit 0), since the POKEd byte’s most-significant bit maps to the leftmost pixel.

UDG Label

Line 30 uses three UDG characters ([UDG-B], [UDG-I], [UDG-N]) to display a custom “BIN” label, indicating the author has defined UDGs for those letters — a common cosmetic touch to produce styled headings without using the standard font.

Notable Idioms

  • PAUSE 0 on line 80 halts execution until a key is pressed, a standard wait idiom.
  • Chaining PAUSE 0:CLS :GO TO 10 on a single line keeps the loop tight and saves memory.
  • The variable name l (lowercase L) could be visually confused with the digit 1 in printed listings — a minor readability concern.

Limitations and Anomalies

The technique requires that the POKEd memory location at 65376 falls within the display file and is not overwritten by other screen activity between lines 20 and 60. The input is not range-checked, so values outside 0–255 would either be truncated by POKE or produce an error. Additionally, the pixel row at coordinate 175 is near the bottom of the display and may overlap with printed output depending on screen layout, potentially corrupting the POINT readback if any PRINT statement renders to that area before the loop completes.

Source Code

    2 REM  by Stan Livingston,   SINCUS "enter dec # for input"
    5 REM decbi6line
   10 INPUT l
   20 POKE 65376,l
   30 PRINT "[UDG-B][UDG-I][UDG-N] ";
   40 FOR m=0 TO 7
   50 PRINT POINT (m,175);
   60 NEXT m
   70 PRINT " = ";l;" DEC"
   80 PAUSE 0:CLS :GO TO 10
 9998 SAVE "DEC TO BIN" LINE 1

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.