Saturday, January 7, 2012

32 bit or 64 bit

Write a C code to find whether a machine is 32 bit or 64 bit.

2 comments:

  1. All compilers keep the size of integer/void* the
    same as the size of the register on a particular architecture. Thus, to
    know whether the machine is 32 bit or 64 bit, just see the size of
    integer/void* on it.

    int main(void){
    switch(sizeof(void*)){
    case 4: printf("32\n");
    break;
    case 8: printf("64\n");
    break;
    }
    }

    ReplyDelete
  2. Said in a very simple way, 32bit CPUs process data in 32-bit chunks, while 64bit CPUs process data in 64-bit chunks. Perhaps the main advantage is that with a 32-bit register one can address 2^32 memory addresses (about 4 GB of RAM), while 64-bit registers can address 2^64 addresses (17.2 billion GB of RAM). Also, a 32bit CPU must process 64-bit numbers in two steps, while 64bit CPUs only require one step.

    Please note that 64bit does not mean twice the performance of 32bit: indeed 64bit code may run slower due to its higher memory consumption, and hence a larger number of cache misses (failed attempts to read or write a piece of data in the cache, which results in a main memory access with much longer latency).

    http://www.iac.es/sieinvens/siepedia/pmwiki.php?n=Tutorials.32vs64bits

    http://en.wikipedia.org/wiki/32-bit

    http://en.wikipedia.org/wiki/64-bit

    ReplyDelete