Bit Shifting in Basic

efren6 67 points 12 comments November 16, 2026
subethasoftware.com · View on Hacker News

Discussion Highlights (3 comments)

pcwalton

You can shift an integer 1 bit to the left by adding it to itself. This should be faster than multiplying by 2 on ancient CPUs.

JdeBP

The interesting thing is that there were BASICs where one could do this more directly. The early Microsoft BASICs for OEM home computers, as Commodore and Tandy BASICs here, are not the only games in town at 50 years's remove. Picking the 1970s BASICs misses out on what one could actually do a handful of years later, as vendors improved BASIC with these new ideas like 16-bit processors and whatnot. (-: TrueBASIC was done by the Darthmouth people themselves in the middle 1980s, and had BIN$() and CONVERT() to convert a number to and from its binary representation as a string of one and zero characters. TurboBASIC had binary numbers as first class numeric literals, &Bxxxxxx, and BIN$(). Sinclair SuperBASIC for the QL had PEEK_W and PEEK_L, so one didn't have to do the tedious byte multiplication. BBC and ARM BASIC had the pling ('!') operator likewise for word instead of byte accesses. When it comes to Unix: Thompson's bas(1) from 1972 did not have any of this, and neither did the DEC PDP basic(6) that was left out of Unix 2nd Edition. But again, that was the 1960s and 1970s. All of these years later we have yabasic that has (alas!) C-style rather than the conventional BASIC-style constants for hexadecimal and binary and bin$() and dec() functions for the string to number conversions in binary, in C style.

bitwize

It never occurred to you to POKE a machine-code routine into memory to do this fast? You can do this with many home-computer BASICs. Sadly not TI BASIC (TI-99/4A), at least not without Extended BASIC and the PEB, but most machines of the day were not so limited as that one.

Semantic search powered by Rivestack pgvector
3,874 stories · 35,194 chunks indexed