
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

void printbits ( int i ) // This function takes an integer i, where 0 <= i < 256, and // outputs it in the form of an 8-bit string. // Precondition: Parameter i is an integer with the range of [0, 255]. // Postcondition: The binary representation of i is output. { string bits[16] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"}; cout << bits[i/16] << bits[i%16] << " "; }