Format specifier x

前端 未结 4 830
离开以前
离开以前 2021-02-01 15:19

I have a simple program :

#include 
int main()
{
        long i = 16843009;
        printf (\"%02x \\n\" ,i);
}

I am using

4条回答
  •  梦谈多话
    2021-02-01 15:50

    You are actually getting the correct value out.

    The way your x86 (compatible) processor stores data like this, is in Little Endian order, meaning that, the MSB is last in your output.

    So, given your output:

    10101010

    the last two hex values 10 are the Most Significant Byte (2 hex digits = 1 byte = 8 bits (for (possibly unnecessary) clarification).

    So, by reversing the memory storage order of the bytes, your value is actually: 01010101.

    Hope that clears it up!

提交回复
热议问题