Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- /* Converting binary number to decimal */
- int conv(long bin);
- main()
- {
- long binary;
- int decimal;
- puts("enter binary number");
- scanf("%ld", &binary);
- printf("%d\n", conv(binary));
- return 0;
- }
- int conv(long bin)
- {
- int i = 0, num, decimal = 0;
- while (bin != 0) {
- num = bin % 10;
- decimal += pow(2,i) * num;
- ++i;
- bin /= 10;
- }
- return decimal;
- }
Advertisement
Add Comment
Please, Sign In to add comment