Question: In C: Write a function void paritize (void *p, unsigned int num bytes); that accepts a void pointer that points to an array of bytes
In C: Write a function void paritize (void *p, unsigned int num bytes); that accepts a void pointer that points to an array of bytes in memory along with the number of bytes the pointer points to, and (1) for each byte, the function computes its parity bit. For a given byte, the parity bit p is 1 if the number of 1s in the first 7 bits (i.e., if a byte were b7b6b5b4b3b2b1b0 then b6 through b0 are the first 7 bits) is odd, or 0 if the number of 1s is even. Then (2) the function replaces the most significant bit (i.e., bit b7) in the byte with the parity bit.
Sample input and expected output:
byte-array that p points to (before calling paritize) in Hex:deadbeef num bytes: 4 byte-array that p points to (after calling paritize) in Hex: de2dbe6f
byte-array that p points to (before calling paritize) in Hex:0 num bytes: 1 byte-array that p points to (after calling paritize) in Hex: 0
byte-array that p points to (before calling paritize) in Hex:1 num bytes: 1 byte-array that p points to (after calling paritize) in Hex: 81
byte-array that p points to (before calling paritize) in Hex:12345678deadc0de num bytes: 8 byte-array that p points to (after calling paritize) in Hex: 12b45678de2dc0de
To test:
int main{
unsigned long x = 0x12345678deadc0de;
paritize(&x, sizeof(x));
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
