Question: at the moment I have script which prints out numeric values into bits so for example 

```
print((short) 1);

```

I get a value of `00000001`, but how can I get for this a value like `00000001 00000000` and in case if I print `print((int) 1);` I get a value of `00000001 00000000 00000000 00000000`.
Here is my code:

```
void printbyte(unsigned char x)
{
    for (int i = 0; i < 8; i++)
    {
        if (x & 0x80) cout << 1;
        else cout << 0;
        x = x << 1;
    }
    cout << endl;
}

template <typename T>
void print (T A)
{
    unsigned char *p = (unsigned char *) &A;
    printbyte(*p);
}

int main()
{
    print((short) 1);

    system("pause");
    return 0;
}

```

Answer: 
You can use bitset, it's the easiest way. Here's an example:

```
#include <iostream>
#include <bitset>

using namespace std;

int main ()
{
 int number;
 cin>>number;
 bitset <16> end (number);
 cout<<number<<" --> "<<end<<'\n';
 return 0;
}

```

Or reference: <http://www.cplusplus.com/reference/bitset/bitset/>

If you not want to use standard solutions, it can also look like this: 

```
#include <iostream>
#include <climits>
using namespace std;

template <typename Type>
void bprint(Type in)
 {
  unsigned char* p = (reinterpret_cast<unsigned char*>(&in))+(sizeof(Type)-1); //x86
  for(unsigned int n = sizeof(Type);n--;--p, std::cout<<' ')
   for(unsigned int i = CHAR_BIT;i--;)
    std::cout<<((*p&char(1<<i))!=0);
  std::cout<<'\n';
 }

int main(void)
{
 int number;
 cin>>number;
 bprint(number);
 bprint(short(number));
 bprint(char(number));
return 0;
}

```

"unsigned" before "char\*" is required, if it isn't set by default. Access to variable's memory has only a pointer of variable's type or unsigned char, according to standard.

The most interesting option is the use of mathematics, described, inter alia, by Gynvael Coldwind, here: <http://gynvael.coldwind.pl/n/c_cpp_number_to_binary_string_01011010> .
I think you should use [std::bitset](http://www.cplusplus.com/reference/bitset/bitset/), but you always have to specify the size at compile time.
To avoid that, you can use a template function like this (note that this is C++11):

```
#include <iostream>
#include <bitset>
#include <limits>

template <class T> void PrintBits (const T &Number) {
    std::bitset<std::numeric_limits<T>::digits> Bit_Number(Number);
    std::cout << Bit_Number << std::endl;

}

```