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

Can you help me write these functions in C? I do not need the main function. Tha

ID: 3796349 • Letter: C

Question

Can you help me write these functions in C? I do not need the main function. Thank you. The language is C, NOT C++

in vertBits Description: Accepts a pointer of size uint32 tand inverts eachbit of the input data passed Preconditions: Input argument is passed as a pointer Post-conditions: The number of 1s returned Calls: N/A Called by: main int countNumberofones (uint32 t intData) Write a function that counts numberof ls in an integerpassed setBit Description: The functionsets the bit in the specified bit position in an to the specifid value. ue can be a or 0. bitPosition will be between U an Postconditions: The bit of inData at position biPosition will be set to walue Calls: N/A Called by main void setBit(uint32 t inData, uint32 tbitPosition.uint32 t alue hammingDistance Description: Function hammingDistance calculates total number of bits that need to be inverted in order to change inData1 into inData2 orvice versa. Preconditions: The function accepts two unsigned integers as input Postconditions: Thefunction returns the hamming distance Calls N/A Called by: main int hammi tinDatal, unint32 tinData2)

Explanation / Answer

int countNumberofOnes(uint32_t *intData)
{
   *intData = ~(*intData); // inverts each bit in input
  
   uint32_t num = *intData;
   int count =0;
   while(number)
   {
       number &= (number-1);
       count ++;
   }
   return count;
   // return number of 1s in the number
}

void setBit(uint32_t *intData, uint32_t bitPosition,uint32_t value)
{
   (*intData) ^= (-value ^ ((*intData)) & (1 << bitPosition);
  
   return (*intData);
  
}

int hammingDistance(uint32_t inData1,uint32_t inData2)
{
   char * d1 =(char *)intData1;
   char * d2 =(char *)intData2;
  
   int count =0;
  
   // considering both of same length
   for (int i=0;i<strlen(d1);i++)
   {
       if(d1[i]!=d2[i])  
           count ++;
   }
  
   return count;
}

Please let us know for any doubts.