Answer the question
In order to leave comments, you need to log in
How is data stored in computer memory?
I'm just starting to learn programming and it's not entirely clear to me how data (for example, char or int) is stored in computer memory.
I'm not talking about two's complement or how a number is represented as 0's and 1's. What I'm interested in is exactly how it's stored at the bit level.
Let's say we have the number 8 (let it be signed char) which will be represented as binary code as 0 0001 000 (if I'm not mistaken)
The number -8 should be represented as either 1 0001 000 or as two's complement code as 1 111 1000. My first question is related to this, because in the training materials everyone deals with some kind of ephemeral concepts of "more convenient" and "often used". Does the x86 architecture store negative numbers in two's complement or in normal?
The second question is related to writing (and, accordingly, reading) numbers to memory. I'm familiar with pointers, but all the resources say they "refer to a memory location". What is a cell, bit or byte? If a bit, does this mean that, for example, allocating memory for a dynamic array, and creating an array that occupies from 7 to 39 bits, then bits 0-6 will remain unused (after all, we do not have data types that are less than 8 bits)? In my view, with such work with memory, when cleared and written over again, it will inevitably become more and more like Swiss cheese with sections that are not used in any way.
If a memory cell is a byte, then how is a number written to it? Sequential from 0 to 7th?
Answer the question
In order to leave comments, you need to log in
Does the x86 architecture store negative numbers in two's complement or in normal?
If the memory cell is a byte, then how is the number written to it? Sequential from 0 to 7th?
If a bit, does this mean that, for example, allocating memory for a dynamic array, and creating an array that occupies from 7 to 39 bits, then bits 0-6 will remain unused (after all, we do not have data types that are less than 8 bits)? In my view, with such work with memory, when cleared and written over again, it will inevitably become more and more like Swiss cheese with areas that are not used in any way
Questions need to be structured, otherwise there is a stream of questions, and porridge in my head.
A memory cell is a byte.
Writing a number to a byte goes right away, but it can even be several numbers at once.
The bitness of the processor indirectly indicates how many bytes can be processed simultaneously
. Negative numbers are an abstraction for the user. From the processor's point of view, these are just bits.
In programming languages, you can specify a signed or unsigned variable, which will affect how the code is compiled and how it is used.
For example, a signed shortint is a byte, with values from 0 to 255
; an unsigned shortint is a byte, with values from -127 to +127 (something like this, maybe up to +128, you need to look at the wiki)
As for the Swiss cheese - don't waste your time, a lot of memory always remains unused in modern computers. For example, memory is allocated in pages of 64 KB, and if a process does not use them all, it still cannot be used by another process.
What is a cell, bit or byte?
Sequential from 0 to 7th?
and creating an array that takes from 7 to 39 bits, then bits 0-6 will remain unused (after all, we do not have data types that are less than 8 bits)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question