Write a C language function to invert all the bits of a give

Write a C language function to invert all the bits of a given number, and print the number in binary form Example: Input: 255 Output: 1111111100000000 Use the following model to complete your program. char * int_co_binary (int n, char *ps); int print_binary(int num, int bits);

Solution

Answer:

#include <stdio.h>
#include <conio.h>
int int_to_binary(int n);
int main() {
int input;
printf(\"Enter a input number\ \");
scanf(\"%d\", &input);
printf(\"Binary number of %d is %d\", input, int_to_binary(input));

getch();
return 0;
}

int int_to_binary(int n) {
int left_number;
int binary = 0, i = 1;
  
while(n != 0) {
left_number = n%2;
n = n/2;
binary= binary + (left_number*i);
i = i*10;
}
return binary;
}

 Write a C language function to invert all the bits of a given number, and print the number in binary form Example: Input: 255 Output: 1111111100000000 Use the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site