UVa 594 - One Little, Two Little, Three Little Endians

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

 #include <cstdio>
#include <bitset>
using namespace std; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int n;
unsigned int un;
while (scanf("%d", &n) != EOF)
{
un = (unsigned int)n;
bitset<> b(un), bt;
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
bt[i*+j] = b[(-i)*+j];
un = bt.to_ulong();
printf("%d converts to %d\n", n, un);
}
return ;
}
上一篇:HTML