1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include "Header.h"
using namespace std;
unordered_map<char, string> substitute_for =
{
{ 'A', "100 0001" }, { 'B', "100 0010" }, { 'C', "100 0011" }, { 'D', "100 0100" },
{ 'E', "100 0101" }, { 'F', "100 0110" }, { 'G', "100 0111" }, { 'H', "100 1000" },
{ 'I', "100 1001" }, { 'J', "100 1010" }, { 'K', "100 1011" }, { 'L', "100 1100" },
{ 'M', "100 1101" }, { 'N', "100 1110" }, { 'O', "100 1111" }, { 'P', "101 0000" },
{ 'Q', "101 0001" }, { 'R', "101 0010" }, { 'S', "101 0011" }, { 'T', "101 0100" },
{ 'U', "101 0101" }, { 'V', "101 0110" }, { 'W', "101 0111" }, { 'X', "101 1000" },
{ 'Y', "101 1001" }, { 'Z', "101 1010" }
};
string convert(const string& text)
{
string result;
for (auto ch : text)
{
if (isalpha(ch)) result += substitute_for[toupper(ch)];
else result += ch;
}
return result;
}
int main()
{
string text;
cout << "Enter statement you would like to convert to binary: ";
getline(cin, text);
cout << convert(text) << '\n';
}
|