I'm trying to output the binary representation of the number 115 using the code below, but my results shown are incorrect.
I'm expecting 0000 0000 0111 0011 but 0000 0000 0111 1111 is shown.
It seems that after determining a 1 should be shown, that's all it will show.
void Bits::displayShort(short input)
{
cout << endl;
sMask = 1000000000000000;
for (int count = 0; count < 16; count++)
{
if ((input & sMask) == 0)
{
cout << "0";
}
else
{
cout << "1";
}
if (count == 3 || count == 7 || count == 11) { cout << " "; }
sMask = sMask >> 1;
}
cout << endl << endl;
}