Ask Question
16 October, 07:43

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

+2
Answers (1)
  1. 16 October, 08:24
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers