Mar 1, 2018 at 1:38am UTC
Kinda lost on this, I know how to do it in C, also I could probably do it in C++, but we have a requirement to use bit operations to do this. Any help is appreciated. Code is below. I just need to write the function without changing main.
using namespace std;
// printHexadecimal: Writes the hexadecimal representation of word to
// output stream os.
void printHexadecimal(int word, ostream& os);
// printLine: Prints a horizontal line of length hyphens to output stream os
void printLine(int length, ostream& os);
extern const int N = sizeof(int) * CHAR_BIT; // # of bits in an int
// Print heading
cout << setw(9) << "Decimal" << setw(24) << "Binary"
<< setw(27) << "Hexadecimal" << endl;
while (cin >> num)
cout << right << setw(11) << num << setw(3) << " "
<< bitset<N>(num) << setw(4) << " ";
cout << endl;
void printLine(int length, ostream& os)
char ch = os.fill();
os << setfill(’-’) << setw(length) << "-" << setfill(ch) << endl;
Mar 1, 2018 at 2:35am UTC
You're going to delete your post again, so I don't think I'm going to help you further.
Mar 1, 2018 at 2:44am UTC
I am not deleting anymore. Realize it was an abuse of the forum, apologies, mbozzi.