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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
int main()
{
int decimal_array[24] = {0};
int binary_array[144] = // array to convert to 24 dec
{
0,0,0,0,0,0,
0,0,0,0,0,1,
0,0,0,0,1,0,
0,0,0,0,1,1,
0,0,0,1,0,0,
0,0,0,1,0,1,
0,0,0,1,1,0,
0,0,0,1,1,1,
0,0,1,0,0,0,
0,0,1,0,0,1,
0,0,1,0,1,0,
0,0,1,0,1,1,
0,0,1,1,0,0,
0,0,1,1,0,1,
0,0,1,1,1,0,
0,0,1,1,1,1,
0,1,0,0,0,0,
0,1,0,0,0,1,
0,1,0,0,1,0,
0,1,0,0,1,1,
0,1,0,1,0,0,
0,1,0,1,0,1,
0,1,0,1,1,0,
0,1,0,1,1,1,
};
// Binary to decimal
for (int i=0; i<24; i++)
{
int temp = 0;
for (int j = 0; j<6; j++)
temp |= binary_array[i*6 + j] << (5 - j);
decimal_array[i] = temp;
}
for (int i=0; i<24; i++)
printf( "%2d ", decimal_array[i]);
printf("\n");
// ------------ Now reverse the process --------------------
// New Array
int bin_arr[144];
// convert decimal to binary.
for (int i=0; i<24; i++)
{
for (int j = 0; j<6; j++)
{
int mask = 1 << (5 - j);
bin_arr[i*6 + j] = ((decimal_array[i] & mask) != 0);
}
}
// output the new binary array
for (int i=0; i<144; i++)
{
if (i % 6 == 0)
cout << endl;
else
cout << ", ";
cout << bin_arr[i];
}
return 0;
}
|