Question

In: Computer Science

Write a C/C++ program that reads a 8-bit value from the screen, calculate the CRC-16 result,...

Write a C/C++ program that reads a 8-bit value from the screen, calculate the CRC-16 result, and print it on the screen.
The input can be any 8-bit value in the hexadecimal form(with or without Ox), e.g., Al for 10100001
The output can be either in hexadecimal or binary form.
The initialization bits are all ones.
The result XoR bits are all ones
The code should be well commented
Do not use existing packages

Solutions

Expert Solution

#include <stdio.h>

#define MAX 1000

int main()

{

    char binarynum[MAX], hexa[MAX];

    long int i = 0;

    printf("Enter the value for hexadecimal ");

    scanf("%s", hexa);

    printf("\n Equivalent binary value: ");

    while (hexa[i])

    {

        switch (hexa[i])

        {

        case '0':

            printf("0000"); break;

        case '1':

            printf("0001"); break;

        case '2':

            printf("0010"); break;

        case '3':

            printf("0011"); break;

        case '4':

            printf("0100"); break;

        case '5':

            printf("0101"); break;

        case '6':

            printf("0110"); break;

        case '7':

            printf("0111"); break;

        case '8':

            printf("1000"); break;

        case '9':

            printf("1001"); break;

        case 'A':

            printf("1010"); break;

        case 'B':

            printf("1011"); break;

        case 'C':

            printf("1100"); break;

        case 'D':

            printf("1101"); break;

        case 'E':

            printf("1110"); break;

        case 'F':

            printf("1111"); break;

        case 'a':

            printf("1010"); break;

        case 'b':

            printf("1011"); break;

        case 'c':

            printf("1100"); break;

        case 'd':

            printf("1101"); break;

        case 'e':

            printf("1110"); break;

        case 'f':

            printf("1111"); break;

        default:

            printf("\n Invalid hexa digit %c ", hexa[i]);

            return 0;

        }

        i++;

    }

    return 0;

}

Program Explanation

1. Take a hexadecimal number as input and store it in the array hexa.
2. Using switch statement access each bit of the hexadecimal number and print its equivalent binary number in a four bit fashion as shown in the program.
3. Do step 2 for every bit of a input number. Use while loop to do this.

Runtime Test Cases

Output:

Enter the value for hexadecimal a1

Equivalent binary value: 10100001


Related Solutions

Write a Java program that reads a name and displays on the screen.
Write a Java program that reads a name and displays on the screen.
Write a C program that reads an integer value. Assume it is the number of a...
Write a C program that reads an integer value. Assume it is the number of a month of the year; print out the name of that month (Hint: months need to be captured in an array).
In C++, write a program that reads data from a text file. Include in this program...
In C++, write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global variables are the actual data points, the mean, the standard deviation, and the number of data entered. All other variables must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function... ALL LINES...
Write a program in C that takes as input an 8-bit binary number and prints the...
Write a program in C that takes as input an 8-bit binary number and prints the next 10 binary numbers. Define a binary number as int binNum[8]; Use binNum[0] to store the most significant (i.e., leftmost) bit and binNum[7] to store the least significant bit. Ask the user to input the first binary number with each bit separated by at least one space.
Write a C++ program that reads a string from a text file and determines if the...
Write a C++ program that reads a string from a text file and determines if the string is a palindrome or not using stacks and queue
C++ Write a program that reads in a list of 10 names as input from a...
C++ Write a program that reads in a list of 10 names as input from a user and places them in an array. The program will prompt for a name and return the number of times that name was entered in the list. The program should output total number of instances of that name and then prompt for another name until the word done is typed in. For this lab, use the string data type as opposed to char to...
Write a program in c that reads the content from the file and stores each line...
Write a program in c that reads the content from the file and stores each line in an int array in heap(using dynamic memory allocation). For example, let the file has elements following (we do not know the size of files, it could be above 100,000 and contents of the file and make sure to convert file elements to int): 10067 26789 6789 3467
(C++) Write a program that reads a list of integers from the keyboard and print out...
(C++) Write a program that reads a list of integers from the keyboard and print out the smallest number entered. For example, if user enters 0 3 -2 5 8 1, it should print out -2. The reading stops when 999 is entered.
Code is in C Write a program that reads integers from stdin. Once it reaches the...
Code is in C Write a program that reads integers from stdin. Once it reaches the * end of the input, it prints the smallest absolute value among those * of the numbers it read. * * For example, if * 4, 6 -3, 3, -2, 13, -4 * are read from stdin, the program should print 2. * * If the end of file is reached before any integer is seen, the * number printed should be INT_MAX (defined...
IN C++ Write a program that reads in int values from the user until they enter...
IN C++ Write a program that reads in int values from the user until they enter a negative number like -1. Once the user has finished entering numbers, print out the highest value they’ve entered, the lowest value they’ve entered, and the total number of numbers they’ve entered. The negative number they entered should not be taken as one of the values entered.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT