Question
Write a C function sum with the following header. uint32_t sum(unsigned char data[], unsigned int data_bytes) The value data is a reference to data_bytes bytes
Write a C function sum with the following header.
uint32_t sum(unsigned char data[], unsigned int data_bytes)
The value data is a reference to data_bytes bytes of memory. The function should read each consecutive 4 bytes of data big-endian and treat it as a uint32_t. Return the sum of all these values (mod 2^32). If data_bytes is not a multiple of 4, ignore the last data_bytes mod 4 bytes of the buffer. If p is a pointer to an unsigned char, you can read 4 bytes big-endian into an uint32_t by following this pseudocode.
Read p[0], cast it to uint32_t, shift it left 24 bits,
Read p[1], cast it to uint32_t, shift it left 16 bits,
Read p[2], cast it to uint32_t, shift it left 8 bits,
Read p[3], cast it to uint32_t.
Bitwise-Or these four values.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started