Representing "word" as hexadecimal

I have a homework assignment where i am meant to write a function based on the code below, that prints the hexadecimal representation of word using bit operations.

I understand how to convert from decimal to hexadecimal and all that in c++, but what i dont understand, is how to use bit operations to do so.

I also do not understand what ostream& os means? the instructions state: The function writes the hexadecimal representation of word to output stream os. The function should use bit operations.

thanks!

1
2
3
  void printHexadecimal(int word, ostream& os);

Show us your code :)
std::ostream is the standard write out character stream in C++, in your code, the ostream& os is taking a character stream reference.

Just cooked up a little example:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

void TakeOS(std::ostream& os)
{
	os << "Hello";
}

int main()
{
	TakeOS(std::cout);
	return 0;
}
Topic archived. No new replies allowed.