In my Computer Architecture class, our assignment is to write a program to demonstrate the process that Booth's Algorithm uses to multiply two 8-bit binary numbers. My current issue is finding the correct syntax to make the bit shift work properly. Here's my code so far:
And here's an example of the output:
![Name: BitShiftFail.jpg
Views: 11
Size: 35.7 KB]()
Why aren't the effects of the bit shifts showing?
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <bitset>
using namespace std;
void mCandASR(int);
void multiplierASR(int);
int main()
{
int mCand = 0;
int multiplier = 0;
cout << "Please enter an interger number between -128 and 127.\n\n";
cin >> mCand;
while (mCand < -128 || mCand > 127)
{
cout << "Your number was either less than -128 or greater than 128.\n";
cout << "please enter an integer between -128 and 127.\n";
cin >> mCand;
}
cout << "Please enter an integer between -128 and 127.\n\n";
cin >> multiplier;
while (multiplier < -128 || multiplier > 127)
{
cout << "Your number was either less than -128 or greater than 128.\n";
cout << "please enter an integer between -128 and 127.\n";
cin >> multiplier;
}
//show binary representation:
cout << "You entered: " << bitset<8>(mCand) << " for the multiplicand and " << bitset<8>(multiplier) << " for the multipier.\n\n";
mCandASR(mCand);
cout << endl << endl;
multiplierASR(multiplier);
system("pause");
return 0;
}
void mCandASR(int a)
{
cout << "At iteration 0, our 8-bit binary multiplicand starts out as: " << bitset<8>(a) << endl << endl;
for (int i = 1; i < 8; i++)
{
a >> 1;//warning C4552: '>>' : operator has no effect; expected operator with side-effect
cout << "Iteration " << i << ": " << bitset<8>(a) << endl;
}
}
void multiplierASR(int b)
{
cout << "At iteration 0, our 8-bit binary multiplier starts out as: " << bitset<8>(b) << endl << endl;
for (int i = 1; i < 8; i++)
{
b >> 1;//warning C4552: '>>' : operator has no effect; expected operator with side-effect
cout << "Iteration " << i << ": " << bitset<8>(b) << endl;
}
}
Why aren't the effects of the bit shifts showing?