Program to convert Binary to Decimal
CODE
👇
- #include<stdio.h>
- #include<math.h>
- #include<conio.h>
- int binary_decimal(int n);
- void main()
- {
- int n;
- char c;
- printf("Enter Binary number : ");
- scanf("%d", &n);
- printf("%d in binary = %d in decimal", n, binary_decimal(n));
- getch();
- }
- //Function to convert binary to decimal.
- int binary_decimal(int n)
- {
- int decimal = 0, i = 0, rem;
- while (n != 0)
- {
- rem = n % 10;
- n /= 10;
- decimal += rem * pow(2, i);
- ++i;
- }
- return decimal;
- }
👉Execut👈
//OUTPUT
/*
Enter Binary number : 10110111
10110111 in binary = 183 in decimal
*/
Program to convert Decimal numbers to Binary.
CODE
👇
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int n, c, k;
- printf("Enter a decimal number : ");
- scanf("%d", &n);
- printf("\n%d in binary number system is : ", n);
- for (c = 8; c >= 0; c--)
- {
- k = n >> c;
- if (k & 1)
- {
- printf("1");
- }
- else
- {
- printf("0");
- }
- }
- printf("\n");
- }
👉Execute👈
//OUTPUT
/*
Enter a decimal number : 143
143 in binary number system is : 010001111
*/
//ThE ProFessoR