문제

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.

도움이 되었습니까?

해결책

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.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top