While the answer in itself is easy, I'll contribute to some good coding style advice.
You could, given the code you show, use std::bitset::to_ulong()
and then add, or do whatever you want before converting back.
But there are few style issues on your code, and one who could break some of the logic on future architectures.
The int
datatype is not guaranteed to be 32-bit by the standard. It is guaranteed to represent the integral type the architecture you're compiling for is the most efficient with.
uint32_t
is what you need, it is guaranteed to be 32 bit long, on all architectures.
And, std::bitset
is not really good at it's job. It's not efficient at all for sizes greater than the int
type, as indexing needs to be done, and not more efficient than the int
type if it's below the size of the int type. And, by the fact that the way to do non bitwise operations with it is to cast it to long
, it is not guaranteed that your addition will be faster or even the same speed as if it were with int
.
So , for your usage of it, the most efficient type would definitly be uint32_t
, being unsigned protecting it of some undefined behavior on signed types bitwise operations.
And, while you are at coding efficient and maintanable code, you can read this : Why is "using namespace std" considered bad practice?