C++ Bitset
A limitation of the bitset is that size must be known at compile time i.e. size of the bitset is fixed.
Syntax
Initialization
Uninitialized - all bits set to 0
Initialization with decimal integer
Initialization with binary string
Utility Functions
to_string() | Converts bitset to std::string. |
to_ulong() | Converts bitset to unsigned long. |
to_ullong() | Converts bitset to unsigned long long. |
Convert a number to its binary - 32 bits : string bit = bitset<32>(x).to_string();
Convert a binary representation to the decimal number - 32 bits : long long decimal = bitset<32>(bit).to_ullong();
Reference : https://www.geeksforgeeks.org/cpp-bitset-and-its-application/
Last updated