Reputation: 499
When I run this code on a 64 bit machine :
#include <stdio.h>
int main()
{
int a[10];
printf("%p",&a);
return 0;
}
It outputs :
0x7fffe9ebf984 (14 digits)
In a textbook I found this :
My computer's memory address is 32 bit and is represent in eight hexadecimal digits.
My Questions are :
Why there are two different lengths for addresses in 32 and 64 bit?
How does 8 digits were used to represent address in 32 bit and 14 in 64 bit?
Upvotes: 4
Views: 7353
Reputation: 9599
First things first: The 0x
prefix indicates that what follows is a hexadecimal (base 16) number. The hexadecimal system extends the set of digits in the decimal system (0 through 9) with a, b, c, d, e and f that stand for the decimal numbers 10, 11, 12, 13, 14 and 15, respectively. The reason that we prefer hexadecimal numbers to decimal ones (at least on a machine whose word length is a multiple of four) is that each hexadecimal digit conveniently corresponds to a group of 4 bits (binary digits). For example:
Hexadecimal: 3
Binary: 0 0 1 1
--------------------
Hexadecimal: F
Binary: 1 1 1 1
Usually when we speak of machines being "32-bit" or "64-bit", we're talking about the virtual address length - that is, the number of bits that constitute a memory address from the perspective of a user-mode process. (This will usually, but not necessarily, coincide with the word length.)
On an x86-32 machine, such as an old Pentium, the virtual address size is 32 bits. This means that an address can be written using eight hexadecimal digits. For example, 0x80000000
represents the 2 GiB mark. The fact that the virtual address is 32 bits implies that any given process can only directly refer to 4 GiB of memory (and in practice, the amount of usable memory is even smaller!).
For many applications today, such as large in-memory databases, 4 GiB of virtual memory is too small to hold the data set. This prompted the introduction of 64-bit machines, such as those based on the x86-64 architecture. In theory, a 64-bit machine should be able to address 16 EiB. But, as others have noted, the x86-64 architecture currently limits the virtual address size to 48 bits by requiring them to be in a canonical form.
Incidentally, an address in the lower portion of the canonical address space can be written using 12 hexadecimal digits. As usual, we omit the leading zeros when printing.
It's unlikely that we'll be seeing a complete shift from 32-bit to 64-bit computing anytime soon, if ever. There are still many applications, particularly in embedded systems, where the amount of memory supported by a 64-bit address is simply not required; indeed, 16- and even 8-bit microcontrollers are still very common.
Upvotes: 7
Reputation: 5211
The reason you have 32-bit and 64-bit addresses has to deal with CPU architectures. Older CPUs use 32-bit, but using 32-bit addresses limits you to 4GB of system memory. This is why the change to 64-bit addresses. The system can support many more addresses, and therefore more RAM.
The "0x" in your number is just telling you that it's hex. So it's actually 12 digits, where each digit is 4 bits (48 bits total).
Upvotes: 1
Reputation: 1969
That memory address has 12 digits, not 14. Each digit is an 4 bit word. 12*4 = 48, which is an address space of 256 terabyte. Current CPU only use the lower 48 bits of the full 64 bits address space, because this allowed to build cheaper transistors (we are not going to fully use the memory we could use from 64 bits in the near future). When we reach the 48 bit limit, manufactures will probably create CPUs that really use the full address space of 64 bits, but right now that is not necessary.
Upvotes: 9