5

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

2 Answers 2

8

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
  • Sorry, now that I’ve read my question back, I’ve definitely not made it clear. What I meant was regarding the address space in RAM being 1 byte long, so what would happen to certain data types that are less than a byte like Boolean values and chars within the address space, from Doc Browns answer it seems like the entire space would be written with the value ie all 8 bits would be the Boolean value of true/false in that example. Would I be right in thinking that? I have many many questions about how memory works in computers, and struggle to find answers. Know any good materials t read?
    – jdow
    Apr 22, 2021 at 8:08
  • @jdow I updated my answer, I hope it helps. I learned from Structured Computer Organization by Andrew Tanenbaum which may be overkill just to learn about memory architecture. And you're not supposed to ask for reading material here so hush hush. I am sure there will be manageable articles on the topic on the internet. Apr 22, 2021 at 9:23
  • Thank you very much for the answer, you've absolutely cleared that up for me. Ultimately its up the the compiler to arrange 1 byte worth of data that is used to interpret a value, I think. I also apologise for asking about reading material, as you can imagine I'm very new to this. I'm left with two questions, can memory be addressed in larger chunks than one byte? Also, How are the logical addresses actually created? I understand its during boot up but I'm unsure, you seem to have a solid grasp of the subject, hope you can help.
    – jdow
    Apr 22, 2021 at 13:17
  • @We should not do questions and answers in comments either. I don't want to push it, a lot of members are quite anal about this so I will suffice by saying this is a big topic that involves a lot of history and industrial evolution. The short answer is yes but it needs a lot of context. The book I mentioned earlier is good for it. Or look for data bus width. Apr 22, 2021 at 13:58
  • Another classic tutorial series is "NAND to Tetris"; for this kind of thing it's best to start with a model of the simplest useful computer and work upwards. Build understanding upwards from the physical hardware. When you see what the machine instructions look like it becomes clear.
    – pjc50
    Apr 22, 2021 at 14:49
5

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
  • Thank you Doc Brown for your answer, I absolutely appreciate it. I love the amount of detail you’ve added, you don’t understand how much you have helped! However, reading my question back I don’t think it was very clear. I’ve posted a common below Martin Maat’s answer with some more detail. You seem to know a lot about memory, do you have any good suggestions where to learn more, as I have many “nitty-gritty” questions. :) thank you very much for the response!
    – jdow
    Apr 22, 2021 at 8:14
  • Just a comment; i think historically the storage wasn't organized into bits at all, it was organized into 'char's and 'word's (ref: en.wikipedia.org/wiki/BCPL) Apr 22, 2021 at 9:44
  • @jdow: seems Martin Maat already answered your additional questions. I will add a reference into my answer to another SE post which might be of interest for you.
    – Doc Brown
    Apr 22, 2021 at 15:10
  • Thank you for your help, I've been struggling to find concrete answers to my question for days, you've no idea how much I appreciate it. I am left wondering how memory addresses are assigned though, also struggling to find a concrete answer to that question. Thank you for referencing to the other post too, will certainly have a look.
    – jdow
    Apr 22, 2021 at 15:25
  • @jdow: if you want to learn how memory adressing works, I would recommend you learn the basics of assembly language. Here is a tutorial.
    – Doc Brown
    Apr 22, 2021 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.