12345678910
#include <iostream> #include <bitset> using namespace std; int main() { int b,x = 12; cin>>b; cout<< bitset<b> (x); }
1234567891011121314151617181920212223242526272829303132
#include <iostream> #include <deque> std::ostream& operator<< ( std::ostream& stm, const std::deque<bool>& bits ) { for( const auto& b : bits ) stm << ( b ? '1' : '0' ) ; return stm ; } std::deque<bool> to_bits( std::size_t nbits, unsigned long long value ) { std::deque<bool> bits ; do { bits.push_front( value%2 ) ; value /= 2 ; } while( value > 0 ) ; while( bits.size() < nbits ) bits.push_front(false) ; return bits ; } int main() { std::size_t b ; std::cin >> b ; const int x = 12 ; std::cout << to_bits( b, x ) << '\n' << to_bits( 50, 12345678 ) << '\n' ; }