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, eg
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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.