Question: In this homework you are asked to implement three functions in C. Details of each function is given in the skeleton code provided. Please complete
In this homework you are asked to implement three functions in C. Details of each function is given in the skeleton code provided.
Please complete the implementation of the four functions IN C. Test your functions using the main program given.
#include#include "BitManipulations.h" int main(int *argc, char **argv) { uint32_t Number; uint32_t bitPosition; uint32_t value; int numOnes; uint32_t input1; uint32_t input2; int32_t hDist; value = 1; bitPosition = 21; Number = 15345; numOnes = countNumberofOnes(&Number); setBit(&Number, bitPosition,value); // set bit in bitposition to value hDist = hammingDistance(input1, input2); // Calculates hamming distance printf(" Hamming Distance = %d \t number of Ones : %d ", hDist, numOnes); return 0; }
#include "BitManipulations.h" //************************************************************************************/ // // countNumberofOnes // // Description: Counts the number of 1s in an integer passed as argument // Preconditions:input argument is passed as a pointer // Postconditions:the number of 1s returned // // Calls: N/A // Called by: main // //***********************************************************************************/ int countNumberofOnes(uint32_t *intData) { // Write a function that counts number of 1s in an integer passed } //***********************************************************************************/ //* //* setBit //* //* Description: The function sets the bit in the specified bit position in an to the specifid value. //* Preconditions: Value can be a 1 or 0. bitPosition will be between 0 and 31 (for integer size argument) //* Postconditions: The bit of *inData at position biPosition will be set to value //* //* Calls: N/A //* Called by: main //* //***********************************************************************************/ void setBit(uint32_t *inData, uint32_t bitPosition,uint32_t value) { // Please do not treat the integer as arrays , this question is about bit manipulations // You will need to use bitwise operations to solve this question } //***********************************************************************************/ //* hammingDistance //* Description: Function hammingDistance calculates total number of bits //* that need to be inverted in order to change inData1 into inData2 or vice versa. //* Preconditions: The function accepts two unsigned integers as input //* Postconditions: The function returns the hamming distance //* // Calls: N/A // Called by: main //* //***********************************************************************************/ int hammingDistance(uint32_t inData1, unint32_t inData2) { } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
