# Boolean subset confusion

#1

Forgive if this topic is covered extensively in a multitude of different locations, but perhaps this will get everyone thinking fundamental language implementation:

why is a Boolean a subset of Integer with 8 bits.

Clearly only one bit is needed, so what’s the purpose of dedicating 7 more bits to the interpreter

#2

It is unclear what you mean by this. Subtype? But `Bool` isn’t a subtype of either `Int8` or `UInt8`.

It is, however, implemented as an 8-bit primitive type:

The declaration of `Bool` above therefore means that a boolean value takes eight bits to store, and has `Integer` as its immediate supertype. Currently, only sizes that are multiples of 8 bits are supported. Therefore, boolean values, although they really need just a single bit, cannot be declared to be any smaller than eight bits.

What interpreter?

Also, see `BitArray`. The choice between that and an array of `Bool` depends on whether speed or memory use is more important, as querying and flipping a single bit is comparatively more expensive.

#3

Computers typically work in units of Bytes and not in units of Bits, and 1 byte = 8 bits. Therefore, multiples of 8 bits or 1 byte is used.

You can’t address less than 8 bits in memory.

#4

Julia

Thank you

#5

I meant to write subtype not subset

#6

@chakravala okay I think I get it, so although there are 256 possible values, 1 byte is the minimum size that can be addressed? So back to the Boolean
julia> x = true::Bool
true

julia> bitstring(x)
“00000001”

julia> y = false::Bool
false

julia> bitstring(y)
“00000000”

#7

Perhaps you meant the compiler.

Did you expect a different interpretation? What do you want to use it for?

If you just want to use `::Bool` values in computation, they behave like the number `0` and `1` for practical purposes, except that they have a specific type, which is required in some contexts (eg `if`), and cannot accept any other value (I am ignoring some corner cases here).

The actual representation is not that important, except if you are interfacing with C or in some corner cases.