--- title: "DEC TO BIN" id: 70999 type: "computer_media" slug: "dec-to-bin" url: "http://localhost/computer_media/dec-to-bin/" markdown_url: "http://localhost/computer_media/dec-to-bin.md" published_at: "2026-08-25T14:18:24+00:00" modified_at: "2026-08-25T14:21:02+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "Convert any decimal number to binary using a clever hardware trick — POKEing a value into display memory and reading pixels back with POINT." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" indiv: - name: "Stan Livingston" slug: "stan-livingston" taxonomy: "indiv" url: "http://localhost/indiv/stan-livingston/" genre: - name: "Utility" slug: "utility" taxonomy: "genre" url: "http://localhost/type/utility/" media_type: "Program" programmers: - name: "Stan Livingston" slug: "stan-livingston" taxonomy: "indiv" url: "http://localhost/indiv/stan-livingston/" download_url: "https://archive.org/download/timex-sinclair-software-archive/DEC%20TO%20BIN%20%28198x%29%28Livingston%2C%20Stan%29%28TS2068%29%28US%29%28Program%29.zip" mediadate: "198x" media_type_tags: "Utility" --- # DEC TO BIN 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 | | --- | --- | | 2 | REM — author/title comment | | 5 | REM — internal program name tag | | 10 | INPUT decimal value into variable `l` | | 20 | POKE value into display memory address 65376 | | 30 | Print “BIN” label using UDG characters | | 40–60 | FOR loop reads 8 pixels with POINT, printing each bit | | 70 | Print the original decimal value as confirmation | | 80 | Wait 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 ```