+1 (315) 557-6473 

Simple Checksum of 10 8-bit Integers Homework Help Using C

Our C programming homework tutors are acquainted with all the concepts and the rules associated with the language. If you avail of our simple checksum of 10 8-bit integers homework help, you are guaranteed superior solutions. Before embarking on preparing your project, our simple checksum of 108-bit integers homework helper familiarize themselves with your instructions first. They do this to ensure that they come up with solutions that meet your expectations.

C program that computes a simple checksum of 10 8-bit integers.

This program is based upon the calculation of the checksum value of an IPv4 header, defined by RFC791.
Your C program should conform to the following specification:
• Program name: checksum
• Reads 10 bytes from standard input (stdin), using the 'read' system call
• Interprets or casts each of these bytes as an integer value in the range of 0..2^8-1 (I.e., 0..255).
• Via a loop, examines each of these bytes in turn,
o computes the running 1's complement sum for 8-bit numbers
o saves the 6th byte into a variable called "checksum", and use the value of zero (0) instead for the calculation of the sum
• Performs the one's complement of the final sum and saves this value to a variable called "complement"
• Outputs the value of "checksum" and "complement" to standard output (stdout) via the printf C library call
• If the value of "checksum" and "complement" is not the same, outputs the string "Error Detected!" to standard error (stderr).
Starter code
#include "stdio.h"
#include "stdlib.h"
#define max_int (255)
#define byte (char)
int main (intargc, char * argv[], char ** envp) {
int count = 10;
int sum = 0;
byte checksum;
byte complement;
  /* the following is the prototype for the read system call */
  /* intread(intfildes, void *buf, size_tnbyte); */
fprintf(stdout, "Stored Checksum: %d, Computed Checksum: %d\n", checksum, complement);
if (checksum != complement ) {
fprintf(stderr, "Error Detected!\n");
return 1;
  }
return 0;
}
 Code Solution
#include
#include
#define max_int 255
#define byte char
int main (intargc, char * argv[], char ** envp) {
int count = 10;
int sum = 0;
byte checksum;
byte complement;
  /* the following is the prototype for the read system call */
  /* intread(intfildes, void *buf, size_tnbyte); */
unsigned char input[10];
inti;
intnum;
  /* read the 10 bytes */
for (i = 0; i< count; i++) {
scanf("%d", &num);
input[i] = num;
  }
for (i = 0; i< count; i++) {
if (i == 5) /* if 6th byte*/
checksum = input[i]; /* use as checksum */
else {
sum += input[i]; /* add to sum */
if (sum >max_int) { /* overflow */
sum = (sum & 0xFF) + 1; /* add carry */
      }
    }
  }
complement = ~sum; /* take one's complement */
fprintf(stdout, "Stored Checksum: %d, Computed Checksum: %d\n", checksum, complement);
if (checksum != complement ) {
fprintf(stderr, "Error Detected!\n");
return 1;
  }
return 0;
}
Related Blogs

C Programming Homework Help – The Best of the Best in the UKThe C programming language is one of the most common languages and the most preferred by the majority of institutions when it comes to introducing learners to programming. Most of the high-level programming languages we have today are a lot...

2020-08-12
Read More

How Can Our Assembly Language Homework Help You Convert CAssembly language is often used in conjunction with C code as it is closer to the metal than Java or other byte code languages. Parameters are passed using the stack (and possibly registers depending on the platform and calling convention). Th...

2020-08-12
Read More

How to Complete Your C Programming Homework with Linux?Almost everyone is familiar with Windows, but a lot of courses use Linux and so you should be prepared to program under Linux. Most programming is similar to Windows but the biggest difference is fork since that has no equivalent on Windows. Whe...

2020-08-12
Read More