2017-07-13 02:59:31 +03:00
|
|
|
/**
|
|
|
|
* Modified 07/12/2017, Kyler Smith
|
2020-05-29 23:23:24 +03:00
|
|
|
*
|
2017-07-13 02:59:31 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int remainder, number = 0, decimal_number = 0, temp = 1;
|
|
|
|
printf("/n Enter any binary number= ");
|
|
|
|
scanf("%d", &number);
|
2017-07-13 02:59:31 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
// Iterate over the number until the end.
|
|
|
|
while (number > 0)
|
|
|
|
{
|
|
|
|
remainder = number % 10;
|
|
|
|
number = number / 10;
|
|
|
|
decimal_number += remainder * temp;
|
2020-06-28 18:25:37 +03:00
|
|
|
temp = temp * 2; // used as power of 2
|
2020-05-29 23:23:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("%d\n", decimal_number);
|
2017-07-13 02:59:31 +03:00
|
|
|
}
|