C Online Compiler
Example: Convert Binary to Decimal in C using Function
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Convert Binary to Decimal in C using Function #include <stdio.h> #include <math.h> int convert(long long x); // It's the driver function int main() { long long x; printf("-----Enter a binary number to convert-----\n"); scanf("%lld", &x); printf("\nThe Binary: %lld => Decimal: %d\n", x, convert(x)); return 0; } // This function will convert number binary to decimal int convert(long long x) { int dec = 0, i = 0, rem; while (x != 0) { rem = x % 10; x /= 10; dec += rem * pow(2, i); ++i; } return dec; }
1010000
Output
Clear
ADVERTISEMENTS