在Intel系列CPU, linux操作系统
声明一个unsigned long long 变量
unsigned long long myULONG = 18264357261189054464;
printf("the myULONG is %llx.\n", myULONG); //fd7808290c000000 我的网卡是 00-0c-29-08-78-fd
为了从myULONG中得到网卡序列
声明 unsigned char netcard[6]; //网卡序列需要6字节, myULONG是8字节
memset(netcard,0,6);
另声明一个临时变量。
unsigned char *temp =(unsigned char *)&myULONG;
由于在Intel系列芯片是little endian----低字节处于内存低位
fd 78-----高位
08 29
0c 00
00 00-----低位
两种方式
netcard[0] = temp[2];
netcard[1] = temp[3];
netcard[2] = temp[4];
netcard[3] = temp[5];
netcard[4] = temp[6];
netcard[5] = temp[7];
============================
或者 myULONG=myULONG>>16;
unsigned char *temp =(unsigned char *)&myULONG;
netcard[0] = temp[0];
netcard[1] = temp[1];
netcard[2] = temp[2];
netcard[3] = temp[3];
netcard[4] = temp[4];
netcard[5] = temp[5];
netcard 中顺序存储了 00 0c 29 08 78 fd