I realize that there is another thread about this topic, where bitshifts are used, but I do not understand why my code is not working:
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<5> b;
int temp=0;
for(int count=0; count<=10; count++)
{ temp=count;
for(int check=4; check>=0; check--)
{
if(2^check<temp)
{
b[check]=1;
temp-=2^check;
}
else b[check]=0;
}
cout<<count<<" "<<b<<endl;
b.reset();
}
}
could someone please help?