Created
January 10, 2020 20:05
-
-
Save misterpoloy/f50eac2e39252039fb89764c0ccb37a4 to your computer and use it in GitHub Desktop.
Decimal to binary
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 <list> | |
std::list <int> decimalToBinary(int n) { | |
std::list <int> binary; | |
int remainder; | |
int number = n; | |
while (number > 0) { | |
int quotient = number / 2; | |
remainder = number % 2; | |
number = quotient; | |
binary.push_front(remainder); | |
}; | |
return binary; | |
}; | |
int main() { | |
std::cout << "Ingresa el número:" << std::endl; | |
int n; | |
std::cin >> n; | |
std::list <int> decimal = decimalToBinary(n); | |
for (int x : decimal) | |
std::cout << x; | |
std::cout << " " << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment