Skip to content

Instantly share code, notes, and snippets.

@SlyCodePanda
Last active May 3, 2018 02:39
Show Gist options
  • Save SlyCodePanda/509c1fb6811eb651f135ce50ef4d15e1 to your computer and use it in GitHub Desktop.
Save SlyCodePanda/509c1fb6811eb651f135ce50ef4d15e1 to your computer and use it in GitHub Desktop.
Base10 to Base2 Converter
#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