Operatory bitowe z maska

0

Program w C++:

  1. Zmiana liczby calkowitej na binarna poprzez operatory bitowe razem z maska i nie moge sobie z tym poradzic pomoglby by ktos?
#include <stdio.h>
#include <stdlib.h>

#include "stdafx.h"
#include <iostream>

using namespace std;


int main(int argc, char *argv[])
{
	cout << "Podaj  liczbe calkowita: \n";
	int n;
	cin >> n;
	int wynik;
	int i = 0;
	unsigned int maska = 2;
	for (int k = 0; k < 32; k++)
	{
		if (n & maska)
		//maska <<= 1;
		wynik = n >> maska;

	}
	cout << "Liczba binarna: " << wynik << endl;
	system ("PAUSE");
return 0;

}
0
unsigned maska =1<<(sizeof(unsigned)<<3);
if(!n) cout<<'0';
else
  {
   for(bool b=false;maska;maska>>=1)
     {
      if(n&maska)
        {
         b=true;
         cout<<'1';
        }
      else if(b) cout<<'0';
     }
  }

1 użytkowników online, w tym zalogowanych: 0, gości: 1