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

Discussion in 'C++' started by hapa_at_1, Oct 28, 2006.

  1. hapa_at_1

    hapa_at_1 New Member

    Joined:
    Oct 28, 2006
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice