ie. "11111111" should convert to 0b11111111 / 255 (in dec)
Try strtol
with a base of 2.
Another possibility would be value = std::bitset<8>("11111111").to_ulong()
. This is more specialized for binary than strtol
, so it could provide advantages if you might want to manipulate some bits. E.g., if you wanted to read a number, flip bit 5, and then convert.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With