checkCPUendian

来源:互联网 发布:网络教育电大 编辑:程序博客网 时间:2024/05/20 18:03
// checkCPUendian.cpp : Defines the entry point for the console application.//#include "stdafx.h"int checkCPUendian(){  union {  unsigned int a;  unsigned char b;              }c;  c.a = 1;  return (c.b == 1);          }   /*return 1 : little-endian, return 0:big-endian*/  bool isBigEndian(){  union {  long l;// a;  char c;//unsigned char b;              }u;  u.l = 1;  if (u.c==1)return false;elsereturn true;          } int main(int argc, char* argv[]){printf("%d\n",checkCPUendian());if(isBigEndian())printf("isBigEndian\n");elseprintf("notBigEndian\n");return 0;}/*1notBigEndianPress any key to continue*/