寫這麼久第一次用到這個語法

真是太神奇了...

不知道那個大大是怎麼想到了 ~"~

讓我對union又更認識了~~

 

一個測試系統是 Big Endian 或  Little Endian的小程式

 

//------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>

typedef union
{
    long l;
    unsigned char c[4];
}Endian_test;

int main()
{
    Endian_test a;
    int i;
    a.l = 0x12345678;
    if (a.c[0] == 0x78)
        printf("This system is 'Little Endian'\n");
    else
        printf("This system is 'Big Endian'\n");
    printf("for a long variable value is 0x%lX\n",a.l); 
    printf("and its storage order in memory :\n"); 
    for(i=0;i<4;i++) 
        printf("%p : 0x%02X\n",&a.c[i],a.c[i]); 
    system("pause");
    return 0;
}

//---------------------------------------------------------

 

題外話 :

記得 這樣編排的目的是一個是存入方便,一個是讀取方便 還要再查一下~"~

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 ffyy99 的頭像
    ffyy99

    喜歡亂搞的世界

    ffyy99 發表在 痞客邦 留言(1) 人氣()