how to add ZERO on beginning of binary number

  c++
void to_binary(int x)
{

    while (x)
    {
        a4 = x % 2;
        x /= 2;
        new_b += a4 * pow(10, g);//g=0
        g++;
    }
}

I wrote the function of converting a number to a binary number system, but there is one but if the number has leading zero, for example, 0011, then I see only 11 in the console. Can I fix this problem? I thought through the vector and bitset but they don`t work for me also.

Source: Windows Questions C++

LEAVE A COMMENT