Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157637
  • 博文数量: 76
  • 博客积分: 1513
  • 博客等级: 上尉
  • 技术积分: 755
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-25 15:15
文章分类

全部博文(76)

文章存档

2012年(2)

2011年(74)

我的朋友

分类: C/C++

2011-11-25 20:23:04

  1. #include <iostream>

  2. #include <sstream>

  3. #include <fstream>

  4. #include <string>

  5. #include <bitset>

  6. #include <stdlib.h>

  7. using namespace std;

  8.  

  9. int main()

  10. {

  11.       char array[4] = {0x01, 0x02, 0x03, 0x04};

  12.       cout << hex << (int)array << "\t" << (int)(array + 1) << "\t"

  13.                   << (int)(array + 2) << "\t" << (int)(array + 3) << endl;

  14.       cout << hex << (int)*array << "\t" << (int)*(array + 1) << "\t"

  15.                   << (int)*(array + 2) << "\t" << (int)*(array + 3) << endl;

  16.       int *b = (int *)array;

  17.       cout << hex << (int)*b << endl;

  18.       if(*b == 0x01020304)

  19.             cout << "Little endian!" << endl;

  20.       else if(*b == 0x04030201)

  21.            cout << "Big endian!" << endl;

  22.       else

  23.            cout << "Error!" << endl;

  24.   

  25. system("pause");

  26.     return 0;

  27. }

Output:

22ff08  22ff09  22ff0a  22ff0b

1       2       3       4

4030201

Big endian!

请按任意键继续. . .

阅读(477) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~