// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>

using namespace std;

char a[8+1];

char *tobin(int v)
{
   int tmp = v;
   for(int i=0;i<8;i++)
   {
      a[7-i] = '0' + tmp % 2;
      tmp = tmp / 2;
   }
   a[8] = '\0';
   return a;
}

int main()
{
   cout << tobin(0) << endl;
   cout << tobin(1) << endl;
   cout << tobin(9) << endl;
   cout << tobin(65) << endl;
   cout << tobin(255) << endl;
   return 0;
}
