Welcome to W3Courses
 Like Us on Facebook

Source Code to Change any Number in Base 10 to Base 2 or Binary in C Programming

Following source code will change any number in base 10 to base 2 or binary in C Programming.

void printit(int num)
{
 if (num)
 {
  int rem = num%2;
  printit(num/2);
  putchar('0'+rem);
 }
}
main()
{
 int num;
 printf("Enter a number: ");
 scanf("%d", &num);
 printit(num);
 printf(" base 2\n");
}

Share