std::bitset<N>::to_string
From cppreference.com
template< class CharT, |
(until C++11) | |
template< class CharT = char, |
(since C++11) | |
Converts the contents of the bitset to a string. Uses zero
to represent bits with value of false and one
to represent bits with value of true.
The resulting string contains N
characters with the first character corresponds to the last (N-1
th) bit and the last character corresponding to the first bit.
Parameters
zero | - | character to use to represent false |
one | - | character to use to represent true |
Return value
the converted string
Exceptions
May throw std::bad_alloc from the the std::string constructor.
Example
Run this code
#include <iostream> #include <bitset> int main() { std::bitset<8> b(42); std::cout << b.to_string() << '\n' << b.to_string('*') << '\n' << b.to_string('O', 'X') << '\n'; }
Output:
00101010 **1*1*1* OOXOXOXO
See also
returns an unsigned long integer representation of the data (public member function) | |
(C++11) |
returns an unsigned long long integer representation of the data (public member function) |