Question

I understand I can use the library bitset to handle binary input and operations on it.

I want to xor certain bits on the input and perform shifting in the binary sequence the user has entered.

I think it can be done in an array, but how can I put each bit in an array element?

An example will be really helpful.

Était-ce utile?

La solution

You can operate directly on the std::bitset as if it were an array, because the [] operator is conveniently overloaded for you, e.g.

std::bitset a, b, c;

for (i = 0; i < a.size(); ++i)
    c[i] = a[i] ^ b[i];    // c = a XOR b

(Note: this assumes that a, b and c all have the same size.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top