Created
January 21, 2022 06:14
-
-
Save cryskram/63e5b470284d4dc686c7621221e44173 to your computer and use it in GitHub Desktop.
A Program to convert Binary to Decimal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
int main() | |
{ | |
long long num, dec = 0, raised = 0, rem; | |
std::cin >> num; | |
while (num != 0) | |
{ | |
rem = num % 10; | |
num /= 10; | |
dec += rem * std::pow(2, raised); | |
raised++; | |
} | |
std::cout << "Decimal is: " << dec << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment