14/02/13 11:58
Saik
Grazie mille ho buttato giu' questo:
#include <bitset>
using std::bitset;
#include <fstream>
using std::fstream;
#include <iostream>
void displayBits(unsigned value);
#include <string>
using std::string;
using std::cout;
int main()
{
fstream out("out.txt",std::ios::out);
string st = "01010101";
const unsigned a = 1 << 8*sizeof(unsigned) - 1 ;
unsigned result = 0 ;
cout << "result :";
displayBits(result);
cout << "a :";
displayBits(a);
for(int i = st.size(); i > 0; i--)
{
if(st[i] == '1')
{
result ^= a;
}
result >>= 1;
cout << i << " ";
displayBits(result);
}
displayBits(result);
std::cin >> result;
return 0;
}
void displayBits(unsigned value)
{
const int SHIFT = 8*sizeof(unsigned) - 1;
unsigned MASK = 1 << SHIFT;
for(int i = 1; i <= SHIFT + 1;i++)
{
cout <<(value & MASK ? '1' : '0');
value <<= 1;
}
cout << std::endl;
}
ovviamente è da migliorare
aaa