Sorry if this sounds like a stupid question I’m very new to this.
So my question is; within modern computers memory address space is a byte long, so what would happen to the rest of the address space if left unused as some data types like booleans use 1 bit of space.
I understand slack space within other block devices, but I’m not sure if it would be similar.
Detailed answers about what actually happens under the hood would be greatly appreciated.
0
While all true and interesting in the context, Doc Brown’s answer does not addresses the question the way I interpret it. The point is, in any microprocessor a byte is the smallest writable data unit. So whether you only care about a single bit or about all 8 bits, you will write 8 known bits for each byte. There is no such thing as missing bits or empty bits.
The programming language may hide the bits you don’t care about for you or only use one particular bit when it comes to interpreting a value but the other bits will still be set explicitly by the machine code instruction that writes the byte.
So, in other words… The programming language (whichever) presents a model. It implements that model using whatever the machine has to offer. Note that on the machine level there are no data types, just bits that are writable in chunks of 8.
This makes your question moot. The machine does not know whether the byte it writes is (part of) a boolean or a character or a floating point value. This information is not in the data itself, the data is just bits. The executed program (or rather the programmer or compiler) knows that that particular byte at that address represents a boolean value and will interpret it as such, ignoring bits that are irrelevant to the type.
7
The exact behaviour depends on the specific programming language implementation (the compiler or interpreter and its version), and the specific platform.
For almost any higher-level programming language environment I have worked with over the last ~40 years which had something like a specific boolean type (which excludes assembly languages or Microsoft Basic V2), the standard memory size for an unpacked boolean variable was 1, 2, 4 or 8 bytes. A “false” value is usually mapped to the integer equivalent of zero (so all bits within the byte or bytes set to zero), and a “true” value either to a representation equivalent to an integer “1”, with exactly one bit set to “one”, all others to zero, or a representation equivalent to “-1”, where all bits are set to “one”. I have also worked with representations where “false” was mapped to the one-byte ASCII character ‘0’ (= decimal 48 = 00110000 binary), and “true” to the one-byte ASCII character ‘1’ (= decimal 49 = 00110001 binary), and maybe some others I probably forgot. It is also not uncommon in certain programming languages like C to interpret every number different from zero as boolean “true”.
Of course, most programming language environments allow to use (or provide) datatypes for arrays of booleans which are packed in some form, so to put up to 8 boolean values into a byte.
Let me add I am pretty sure there exist some other language environments with different conventions, but I guess those are not really “mainstream”. You will find some further information for several different languages here: Rosetta Code – Boolean values. For more information about the low-level functionality of computers, you may have a look into “How Do Computers Work?”.
5