2
I’m holding up programming and I’m making a code where I’m supposed to turn a binary code into a phrase. I’m turning the binary value into decimal, and taking the decimal value and comparing the ASCII table. However, I don’t know how to keep 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;
}
give a read in the vector library of c++ (vector) or create a string variable (string library) and use it concatenating the obtained values. For more information about string: http://www.cplusplus.com/reference/string/string/ E for vector: http://www.cplusplus.com/reference/vector/vector/
– Lucas Trevisan
Thanks Lucas, I’ll take a look.
– Armoz
I read your code, I didn’t fully understand the purpose and the specific difficulty.
– Maniero
I don’t know how to store this conversion ex: 01010000 is equal to 80 which is equal to 'P' in the ascii table and 01110010 is equal to 114 which is equal to 'R'. How I put this 'P' and 'R' together and make them show side by side at the end of the show?
– Armoz
I still don’t understand what you want, which is a shame because the question sounds interesting. Before learning to program you need to learn to understand the problem and communicate it clearly, then programming becomes easier. Programming is detail, details are missing. This looks like a jumble of information. Maybe I understand something, but then your code doesn’t go anywhere near what you’re saying.
– Maniero
Pera ai vamos por partes kk I have to take a series of binary codes and convert them to the ASCII table, IE, have a message in binary code that I have to convert it to characters and form the phrase.
– Armoz
There’s nothing standard in the code and there’s no explanation for how you intend to do it, let alone a code that handles it.
– Maniero
It’s an exercise, Make a program that translates any message into binary! This code above is what I’m trying to do. I’m learning to program in C/C++, sorry if it’s too out of character kk
– Armoz