binary representation

how can i print the representation of number in any-bit binary complement code?
i don't want bitset<4> or bitset<8> bitset<16> and etc. i want something like that bitset<n> and i whan i input da n the program output n-bit binary number
1
2
3
4
5
6
7
std::string bits( unsigned long long number, std::size_t nbits )
{
    std::string str ;
    for( ; number > 0 ; number /= 2 ) str += char( number%2 + '0' ) ;
    if( nbits > str.size() ) str.resize( nbits, '0' ) ;
    return { str.rbegin(), str.rend() } ;
}

http://coliru.stacked-crooked.com/a/acafc3f43350dbad
Complement code - 1

Given numbers a and n, print the representation of a in n-bit binary complement code.

Print a line with n digits containing the representation of number a in n-bit binary complement code, where the first digit is the highest bit.

Input

In one line given two numbers a and n (2 ≤ n ≤ 16, -2n-1 ≤ a ≤ 2n-1-1).

Output

Print the number in n-bit complement code.
Input example
Sample 1
5 8

Sample 2
-5 8
Output example
Sample 1
00000101

Sample 2
11111011
Topic archived. No new replies allowed.