I'm holding programming and am making a code where I must turn a code into binary in a sentence. I'm turning the binary value into decimal, and getting the decimal value and comparing the ASCII table. But I do not know how to save the letters that appear in a variable or vector to display them all together at the end.
int main()
{
setlocale(LC_ALL, "Portuguese");
int dec=0,num,d=1;
char charr[25];
cout<<" Digite o numero binario de 8 dígitos (dígite 0 para parar): ";
cin>>num;
do {
dec = dec+(num%10)*d;
d = d*2;
num = num/10;
}
while(num!=0);
charr[0] = 'A', charr[16] = 'Q';
charr[1] = 'B', charr[17] = 'R';
charr[2] = 'C', charr[18] = 'S';
charr[3] = 'D', charr[19] = 'T';
charr[4] = 'E', charr[20] = 'U';
charr[5] = 'F', charr[21] = 'V';
charr[6] = 'G', charr[22] = 'W';
charr[7] = 'H', charr[23] = 'X';
charr[8] = 'I', charr[24] = 'Y';
charr[9] = 'J', charr[25] = 'Z';
charr[10] = 'K';
charr[11] = 'L';
charr[12] = 'M';
charr[13] = 'N';
charr[14] = 'O';
charr[15] = 'P';
if (dec == 65 or dec == 97)
{
cout<<charr[0];
}
if (dec == 66 or dec == 98)
{
cout<<charr[1];
}
if (dec == 67 or dec == 99)
{
cout<<charr[2];
}
if (dec == 68 or dec == 100)
{
cout<<charr[3];
}
if (dec == 69 or dec == 101)
{
cout<<charr[4];
}
if (dec == 70 or dec == 102)
{
cout<<charr[5];
}
if (dec == 71 or dec == 103)
{
cout<<charr[6];
}
if (dec == 72 or dec == 104)
{
cout<<charr[7];
}
if (dec == 73 or dec == 105)
{
cout<<charr[8];
}
if (dec == 74 or dec == 106)
{
cout<<charr[9];
}
if (dec == 75 or dec == 107)
{
cout<<charr[10];
}
if (dec == 76 or dec == 108)
{
cout<<charr[11];
}
if (dec == 77 or dec == 109)
{
cout<<charr[12];
}
if (dec == 78 or dec == 110)
{
cout<<charr[13];
}
if (dec == 79 or dec == 111)
{
cout<<charr[14];
}
if (dec == 80 or dec == 112)
{
cout<<charr[15];
}
if (dec == 81 or dec == 113)
{
cout<<charr[16];
}
if (dec == 82 or dec == 114)
{
cout<<charr[17];
}
if (dec == 83 or dec == 115)
{
cout<<charr[18];
}
if (dec == 84 or dec == 116)
{
cout<<charr[19];
}
if (dec == 85 or dec == 117)
{
cout<<charr[20];
}
if (dec == 86 or dec == 118)
{
cout<<charr[21];
}
if (dec == 87 or dec == 119)
{
cout<<charr[22];
}
if (dec == 88 or dec == 120)
{
cout<<charr[23];
}
if (dec == 89 or dec == 121)
{
cout<<charr[24];
}
if (dec == 90 or dec == 122)
{
cout<<charr[25];
}
return 0;
}