A signed 1-bit type?

Quirin Schroll qs.il.paperinik at gmail.com
Tue Sep 19 12:37:59 UTC 2023


I don’t know if what I’m going to say is trivial or interesting, 
but I had this thought only recently, thinking about the design 
of an integer type system.

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?

Yes. If we think of booleans as 1-bit numeric types, it boils 
down to the question of mere signedness. If we assume 2’s 
complement, a signed 1-bit type has the values −1 and 0; that’s 
how 2’s complement works. Of course an unsigned 1-bit type has 
the values 0 and 1.

I cannot answer you why you’d want a signed 1-bit type, though.

D’s booleans, however, are unsigned integer types.


More information about the Digitalmars-d mailing list