A signed 1-bit type?
Paul Backus
snarwin at gmail.com
Thu Sep 21 18:23:50 UTC 2023
On Tuesday, 19 September 2023 at 12:37:59 UTC, Quirin Schroll
wrote:
> In Visual Basic (and probably more Basic dialects), booleans
> convert to integers as `False` → 0 and `True` → −1. You read
> that correctly, it’s *minus* one. A weird choice, isn’t it? But
> could it come from a basic principle?
I did some searching, and this convention goes back at least as
far as 8-bit Microsoft Basic [1], though not all the way to the
original 1964 version of Dartmouth Basic [2].
I think a more likely explanation is that -1 was chosen because
its binary representation is the bitwise inverse of 0. This
allows the language to use the same operator for both bitwise and
logical "not". Given how scarce memory was at the time,
space-saving tricks like this were probably hard to pass up.
[1] https://archive.org/details/c64-programmer-ref
[2] https://www.dartmouth.edu/basicfifty/basicmanual_1964.pdf
More information about the Digitalmars-d
mailing list