1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <iostream>
#include <bitset>
using namespace std;
typedef bitset<8> Byte;
int main()
{
int i,j;
int array[32]=
{
1,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
1,1,0,0,0,1,1,1,
0,1,0,1,1,0,0,0
};
Byte result[4];
for (i=0; i<4; i++)
{
for (j=0; j<8; j++)
result[i][8-j-1]=array[i*8+j];
}
for (i=0; i<4; i++)
{
cout << result[i].to_ulong();
cout << " (";
cout << result[i].to_string<char,
char_traits<char>,allocator<char> >();
cout << ')' << endl;
}
cout << "\nhit enter to quit...";
cin.get();
return 0;
}
| |