Ask Question
6 November, 13:45

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. 6 November, 16:28
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers