Little vs Big Endianess: How to interpret the test

前端 未结 6 955
长发绾君心
长发绾君心 2020-12-11 03:44

So I\'m writing a program to test the endianess of a machine and print it. I understand the difference between little and big endian, however, from what I\'ve found online,

6条回答
  •  天命终不由人
    2020-12-11 03:57

    Here's what the memory will look like, assuming a 32b integer:

    Little-endian
    0x01000000 = 00000001000...00
    
    Big-endian
    0x00000001 = 0......01
    

    Dereferencing a char * gives you one byte. Your test fetches the first byte at that memory location by interpreting the address as a char * and then dereferencing it.

提交回复
热议问题