need help displaying hex values

Below is a program which loads a file and then displays a binary representation of its contents. I need to modify it to display the hex representation. I think I understand most of the code, but I don't get what the following excerpt is about:

value = value << 1;
if (bit == '1')
value = value | mask;

which is found in the writebit() method in the code below. Could anyone help me to understand this? Am I right to assume that modifying this chunk is the key to solving this problem?