int Bit(long x, unsigned int n)
{
if(x > 0)
{
//create long sigNum instead of using x, for debugging purposes//
long sigNum = x;
n = n-1;
//shiting the bit so the most significant is the least ssignificant bit//
sigNum = sigNum >> n;
//anding the result with one to get rid of the uninportant bits//
sigNum = sigNum & 1;
if(sigNum == 1)
{
return 1;
}
else
{
return 0;
}
}
if(x = 0)
{
return 0;
}
}
int main()
{
cout << "BINARY BITWISE AND CONVERSION. \n";
long integer;
cout << "Please enter an integer: ";
cin >> integer;
unsigned int sigBit;
cout << "Please enter the bit number you are interested in:";
cin >> sigBit;
int SigBitwise = Bit(integer,sigBit);
cout << "The binary representation of the significant bit you're after is: ";
cout << SigBitwise << "\n";
cout << "The binary representation of the whole decimal is: ";
/*int binary;
for(int i = 1; i < 32; i++)
{
binary = SigBitwise(integer,i);
cout << binary;
}
*/
cout << "\n";
return 0;
}
where i have commented
for(int i = 1; i < 32; i++)
{
binary = SigBitwise(integer,i);
cout << binary;
}
i'm getting a compiling error: 'SigBitwise' cannot be used as a function.
all i want to do is keep returning the bit function so i can get my binary representation,
ok i switch the loop around as it was doing the opposite as i wanted it to do.
i.e 3 would be 110000000000000000000000000000000
instead it's now the correct 000000000000000000000000000000011
i'm still having trouble using the same method for the negative numbers!
how would i write test cases for the bit function?!
i'm really new to c++ but i've come from a background (well, i recently did a semester) of Javascript.