小编Eph*_*ral的帖子

C、小端和大端混淆

我试图理解 C 编程内存字节顺序,但我很困惑。我在此站点上尝试使用我的应用程序进行输出验证:www.yolinux.com/TUTORIALS/Endian-Byte-Order.html

对于我在 C 程序中使用的 64 位值:

volatile long long ll = (long long)1099511892096;
__mingw_printf("\tlong long, %u Bytes, %u bits,\t%lld to %lli, %lli, 0x%016llX\n", sizeof(long long), sizeof(long long)*8, LLONG_MIN, LLONG_MAX , ll, ll);

void printBits(size_t const size, void const * const ptr)
{
    unsigned char *b = (unsigned char*) ptr;
    unsigned char byte;
    int i, j;
    printf("\t");
    for (i=size-1;i>=0;i--)
    {
        for (j=7;j>=0;j--)
        {
            byte = b[i] & (1<<j);
            byte >>= j;
            printf("%u", byte);
        }

        printf(" ");
    }
    puts(""); …
Run Code Online (Sandbox Code Playgroud)

c endianness

0
推荐指数
1
解决办法
1374
查看次数

标签 统计

c ×1

endianness ×1