Ask Question

Write a program that reads a number and prints all of its binary digits: print the remainder number % 2, then replace the number with number / 2. keep going until the number is 0. for example, if the user provides the input 13, the output should be

+5
Answers (1)
  1. 28 April, 22:35
    0
    If you print the binary digits just like that, they'll be in the wrong order (lsb to msb). Below program uses recursion to print the digits msb to lsb. Just for fun.

    void printBits (unsigned int n)

    {

    if (n > 1) {

    printBits (n >> 1);

    }

    printf ((n & 1) ? "1" : "0");

    }

    int main ()

    {

    unsigned int number;

    printf ("Enter an integer number: ");

    scanf_s ("%d", &number);

    printBits (number);

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that reads a number and prints all of its binary digits: print the remainder number % 2, then replace the number with ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers