how can i change my C++ program that converts integer into binary form into 32 bit

hapa_at_1's Avatar
Light Poster
i have written this program

Code:
#include <iostream>
#include <cmath>
using namespace std;

  int main ()
  {
	  int a;
	  int y;
	  a=16;
	  y=a%2;
	  a=a/2;
	  while((a)!=0)
	  {
		  cout<<y;
		y=a%2;
		a=a/2;
	  }
	 cout<<y<<endl;

	  return 0;
  }
their are two problem with this program first that the output that it gives is in inverse that is

integer 16 has its binary represantation as
10000
but the program that i have written gives the output as
00001
how can i reverse my output

and the second problem is that i want the output to be in 32 bit binary representation which i am not able to get how can i alter the program to get the output this way

integer 16 as

0000 0000 0000 0000 0000 0000 0001 0000

help me alter this program

please help as
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Refer Decimal, Hex, octal and binary number inter conversion for number conversion.