Hello. Please answer the attached C programming question correctly. The attached code has to be changed so that it can print a decoded version of the binary number list. Please do not use very advanced syntax to solve the problem. Also, please create a complete file header based on the file header style picture. *If you change the attached code correctly, do not use very advanced syntax, and create the file header, I will give you a thumbs up. Thanks. —----------------------------------------------------------------------------------------------------------------- Code That Needs to Be Changed: #include int bintodec(char *str) { int x = 0; for(int i = 0; str[i] != '\0'; i++) { x = (str[i] - '0') + x * 2; } return x; } void dectobin(int x, char *bin) { for(int i = 0; i < 7; i++) { bin[i] = '0'; } bin[7] = '\0'; int i = 6; while(x != 0) { bin[i] = (x % 2) + '0'; x /= 2; i--; } } int main() { int num=12; char binaryNum[]="00101100"; char binaryRep[8]; int decRep; int i, j; dectobin(num, binaryRep); decRep = bintodec(binaryNum); printf(" Binary representation of %d is %s.\n",num, binaryRep); printf(" Decimal representation of %s is %d.\n",binaryNum, decRep); return 0; } —------------------------------------------------------------------------------------------------------------------ Question: Assume you received a text message in binary, and you need to decode the message. char *binaryMsg = "0101100101101111011101010010000001100110011011110111010101101110011001000010000001110100011010000110010100100000011100110110010101100011011100100110010101110100001000000110110101100101011100110111001101100001011001110110010100101110"; The message is the ASCII code of some characters. Your task is to convert every eight bits of the message to a decimal number. The decimal number is the ASCII code of the character that you need to print. When you print all characters, you will see the message. *Further instructions are in the pictures.
Hello. Please answer the attached C
*If you change the attached code correctly, do not use very advanced syntax, and create the file header, I will give you a thumbs up. Thanks.
—-----------------------------------------------------------------------------------------------------------------
Code That Needs to Be Changed:
#include <stdio.h>
int bintodec(char *str) {
int x = 0;
for(int i = 0; str[i] != '\0'; i++) {
x = (str[i] - '0') + x * 2;
}
return x;
}
void dectobin(int x, char *bin) {
for(int i = 0; i < 7; i++) {
bin[i] = '0';
}
bin[7] = '\0';
int i = 6;
while(x != 0) {
bin[i] = (x % 2) + '0';
x /= 2;
i--;
}
}
int main()
{
int num=12;
char binaryNum[]="00101100";
char binaryRep[8];
int decRep;
int i, j;
dectobin(num, binaryRep);
decRep = bintodec(binaryNum);
printf(" Binary representation of %d is %s.\n",num, binaryRep);
printf(" Decimal representation of %s is %d.\n",binaryNum, decRep);
return 0;
}
—------------------------------------------------------------------------------------------------------------------
Question:
Assume you received a text message in binary, and you need to decode the message.
char *binaryMsg = "0101100101101111011101010010000001100110011011110111010101101110011001000010000001110100011010000110010100100000011100110110010101100011011100100110010101110100001000000110110101100101011100110111001101100001011001110110010100101110";
The message is the ASCII code of some characters. Your task is to convert every eight bits of the message to a decimal number. The decimal number is the ASCII code of the character that you need to print. When you print all characters, you will see the message.
*Further instructions are in the pictures.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images