Another possibility is value = std::bitset<8>("11111111").to_ulong() . This is more specialized for binary than strtol , so it can provide benefits if you want to manipulate some bits. For example, if you want to read a number, flip bit 5 and then convert.
source share