UVa 594

  题目大意:大小端模式的转换。所谓的小端模式,是指数据的高位保存在内存的高地址中,而数据的低位保存在内存的低地址中。与此相对,所谓的大端模式,是指数据的高位,保存在内存的低地址中,而数据的低位,保存在内存的高地址中。以字节为单位,将整数的高低位进行交换即可,可以使用<bitset>。

 1 #include <cstdio>
 2 #include <bitset>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7 #ifdef LOCAL
 8     freopen("in", "r", stdin);
 9 #endif
10     int n;
11     unsigned int un;
12     while (scanf("%d", &n) != EOF)
13     {
14         un = (unsigned int)n;
15         bitset<32> b(un), bt;
16         for (int i = 0; i < 4; i++)
17             for (int j = 0; j < 8; j++)
18                 bt[i*8+j] = b[(3-i)*8+j];
19         un = bt.to_ulong();
20         printf("%d converts to %d
", n, un);
21     }
22     return 0;
23 }
View Code
原文地址:https://www.cnblogs.com/xiaobaibuhei/p/3292271.html