#include using namespace std; int input; // This assignment is worth 5 points. int main() { cout << "Enter a number in base 10: "; cin >> input; // Get rid of all values above 255, the max allowed in 8 bits unsigned input = input % 256; cout << "Least 8 significant binary bits: "; // Get the MSB and print it out, remember to NOT use endl in this case cout << input/128; /* * Knowing that modulo division had already forced the value to be 255 * or less, dividing by 128 now ensures that the value will always be * either 0 or 1. The same logic applies for all subsequent steps. */ // Reduce the value again to prep it for the next bit calculation input = input % 128; // Rinse and repeat for the remaining 7 bits cout << input/64; input = input % 64; cout << input/32; input = input % 32; cout << input/16; input = input % 16; cout << input/8; input = input % 8; cout << input/4; input = input % 4; cout << input/2; input = input % 2; cout << input << endl; // No need for /1 and %1 return 0; }