Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C Programming Write a function that takes, as input, an unsigned 32-bit variable

ID: 3881479 • Letter: C

Question

C Programming

Write a function that takes, as input, an unsigned 32-bit variable x and a 32element array of unsigned 8-bit elements y[]. The function will map the bits in x to the bytes in y[] such that if the nth bit of x is a 1 the nth byte of the array y[] will also equal 1, and if the nth bit of x is a 0 the nth byte of the array y[] will also equal 0. The function should also return an unsigned 8-bit integer that contains the total number of 1s in x. After calling the function, your program should loop through the array y[] and print out each of the elements so that the display in the Serial Monitor looks like a binary vector. In another line, your program should print out the number of 1s returned by the function. I will be testing out your code in class by manually setting the value of x and verifying that the output is correct.

Explanation / Answer

/*This is only a function that performs the above mentioned tasks you need to include standard libraries and header files like 'stdio.h' of c programming language to run this code*/

int myFunction(uint32_t x, int y[])

{

int k;

int count=0;

/*this loop will calculate binary bit given by 'x' at each index of y and assign it to that respective index of y*/

int main()

{

int u[32],r;

r=myFunction(103,u);

printf("%d",r);

}