are address 13,221 and address 13,222 separated by 8 bits? 16? 32?
8 bits, almost always
Does every individual bit have an address?
No, only bytes. One uses other means to get the value of specific bits.
If the size varies, is the specific size determined by hardware? Disk format? Operating system? Compiler/interpreter?
Size does not vary and it is deeply hardware dependent.
If I'm only storing a byte of data in a 16 bit space, how is that implemented? Is it done by defaulting the leftmost 8 bits to 0, like writing '12' as '0012' by way of a base 10 comparison?
I do not really get what you mean by a 16 bits space. If you are considering a 2 bytes memory, every byte has an address (as in every memory) and if a byte is written, it is written at the address given by the computer. So in a 16 bits memory, there are two bytes at addresses 0 and 1.
But maybe you meant "if I have the address of 16 bits word and I use it to write a byte, where will it be written?".
Actually, it depends on the computer. In some computers, address of the word is the address of its least significant byte (they are called little endian and x86 architecture has this charactristic), while for others at the address of the word is its most significant byte and the least significant one is at next address (big endian computers). Many computers can select their endianness at boot time. Actually, it a matter of convention (like writing from right to left or from left to right), but it has deep programming implications. Writing a byte (char
in C) at a the address supposed to hold 2 bytes (short
in C) make programs non portable and is strongly discouraged, unless you really know what you do. If the data type is properly respected, you do not have to worry on the way bytes are arranged in memory.
Is the size flexible somehow to utilize those unused chunks of storage space?
Computers allocate space for variables. Depending on the kind of variable, you have specific space reserved. For instance, in C, a char
is stored in a byte, a short
in two bytes, an int
in 4 bytes most of the time, etc. This insures that whatever value get this variable, if it respects the constraints of its type (for instance an unsigned char
must be between 0 and 255), it will be properly written in the memory. So it is not "unused" space. Adding "flexibility", would render memory management completely unworkable.