--- title: "Decimal to Binary and Binary to Decimal" id: 76393 type: "computer_media" slug: "decimal-to-binary-and-binary-to-decimal" url: "http://localhost/computer_media/decimal-to-binary-and-binary-to-decimal/" markdown_url: "http://localhost/computer_media/decimal-to-binary-and-binary-to-decimal.md" published_at: "2026-11-11T08:02:48+00:00" modified_at: "2026-11-11T08:02:48+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2026/11/decimal-binary-converters-1.png" excerpt: "Two ZX80 programs from Syntax's Computer Number Systems series: decimal numbers to 16-bit binary, and binary numbers back to decimal." post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "ZX80" slug: "zx80" taxonomy: "post_tag" url: "http://localhost/tag/zx80/" model: - name: "Sinclair ZX80" slug: "zx80" taxonomy: "model" url: "http://localhost/model/zx80/" indiv: - name: "William Herron" slug: "herron-william" taxonomy: "indiv" url: "http://localhost/indiv/herron-william/" genre: - name: "Mathematics" slug: "mathematics" taxonomy: "genre" url: "http://localhost/type/mathematics/" media_type: "Program" programmers: - name: "William Herron" slug: "herron-william" taxonomy: "indiv" url: "http://localhost/indiv/herron-william/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Decimal%20to%20Binary%20and%20Binary%20to%20Decimal%20%281981%29%28Herron%2C%20William%29%28ZX80%29%28US%29%28Program%29.zip" mediadate: "1981" images: - url: "http://localhost/wp-content/uploads/2026/11/decimal-binary-converters-1.png" - url: "http://localhost/wp-content/uploads/2026/11/decimal-binary-converters-2.png" article_media: - id: 19248 title: "Computer Number Systems" type: "article" url: "http://localhost/article/computer-number-systems/" related_content: - id: 19783 title: "Computer Number Systems II" type: "article" url: "http://localhost/article/computer-number-systems-ii/" - id: 19768 title: "Computer Number Systems III" type: "article" url: "http://localhost/article/computer-number-systems-iii/" media_type_tags: "Mathematics" license: false --- # Decimal to Binary and Binary to Decimal Two short programs by Bill Herron. Decimal to Binary asks D= for a number from -32768 to 32767 and prints its 16 bits; press NEWLINE for another number, or any other key and NEWLINE to stop. Binary to Decimal asks BI= for up to 28 binary digits and prints DEC=, the decimal value. It ends with CLEAR, so RUN it again for another number. The article explains binary place values and how the ZX80 stores numbers. The download has both programs. Published in Syntax February 1981 ([Computer Number Systems](https://timexsinclair.com/article/computer-number-systems/)). ## Source Code ``` 1 REM DECIMAL TO BINARY 100 PRINT "D="; 110 INPUT D 120 PRINT D 200 PRINT "BI="; 205 LET MSK1=-32767-1 210 FOR Z=1 TO 16 220 PRINT (D AND MSK1)/MSK1; 230 LET MSK1=ABS(MSK1/2) 240 NEXT Z 250 PRINT 1000 INPUT Z$ 1020 IF Z$="" THEN GO TO 100 100 REM BINARY TO DECIMAL 110 DIM X(14) 112 DIM Y(14) 114 LET A=10**4 120 LET X(0)=2**13 130 FOR I=1 TO 14 140 LET X=X(I-1)*2 142 LET C=X/A 144 LET X(I)=X-C*A 150 LET Y(I)=Y(I-1)*2+C 160 NEXT I 170 DIM B(27) 200 PRINT "BI="; 204 INPUT B$ 206 LET F=0 210 FOR I=0 TO 27 220 LET B=CODE(B$) 230 IF B=1 THEN GO TO 292 234 IF B=29 THEN LET F=1 240 IF B<30 AND B>27 AND F>0 THEN GO TO 270 250 LET B$=TL$(B$) 260 GO TO 220 270 LET B(I)=B-28 275 PRINT B(I); 280 LET B$=TL$(B$) 290 NEXT I 292 LET S=I-1 294 IF S<0 THEN GO TO 297 295 PRINT 296 GO TO 300 297 LET S=0 298 PRINT S 300 LET U=0 305 LET L=0 320 FOR I=0 TO S 330 IF B(I)=0 THEN GO TO 380 340 IF S-I>12 THEN GO TO 350 342 LET X=2**(S-I) 344 LET Y=0 346 GO TO 360 350 LET X=X(S-I-13) 352 LET Y=Y(S-I-13) 360 LET L=L+X 362 LET C=L/A 364 LET L=L-C*A 370 LET U=U+Y+C 380 NEXT I 400 PRINT "DEC="; 410 IF U>0 THEN GO TO 413 411 PRINT L 412 GO TO 430 413 PRINT U; 420 PRINT TL$(STR$(L+A)) 430 CLEAR ```