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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!