Last active
May 3, 2018 02:39
-
-
Save SlyCodePanda/509c1fb6811eb651f135ce50ef4d15e1 to your computer and use it in GitHub Desktop.
Base10 to Base2 Converter
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 <bitset> | |
using namespace std; | |
// Convert base 10 number to base 2. | |
string binary(int num) | |
{ | |
bitset<16> bin(num); | |
string binrayString = bin.to_string(); | |
return binrayString; | |
} | |
// Test example. | |
int main() | |
{ | |
int number = 12; | |
cout << number << " in binary is " << binary(number) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment