Please complete the implementation of the four functions IN C.
//************************************************************************************/
//
// 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)
{
}
Main function with the variables, and to test the functions.
#include <stdio.h>
#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("\nHamming Distance = %d \t number of Ones : %d\n", hDist, numOnes);
return 0;
}
/* * BitManipulations.h */ #ifndef BITMANIPULATIONS_H_ #define BITMANIPULATIONS_H_ typedef unsigned int uint32_t; typedef unsigned short uint16_t; #endif /* BITMANIPULATIONS_H_ */
Code:
#include <stdio.h>
#include <stdint.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)
{
uint32_t number = *intData;
// Write a function that counts number of 1s in an
integer passed
int noofOnes = 0;
while (number)
{
int digit = number % 10;
if (digit == 1)
noofOnes++;
number = number / 10;
}
return noofOnes;
}
//***********************************************************************************/
//*
//* 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
//Storing the 32 bit Value
uint32_t number = *inData;
char bitArr[4] = {0};
int index = 0;
while (number)
{
bitArr[(index/8)] |= (number % 2)
<< (index % 8);
number = number / 2;
++index;
}
bitArr[bitPosition / 8] |= value << ((bitPosition - 1) % 8);
}
//***********************************************************************************/
//* 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, uint32_t inData2)
{
//Bit array for inData1
char bitArr1[4] = { 0 };
int index = 0;
while (inData1)
{
bitArr1[(index / 8)] |= (inData1 %
2) << (index % 8);
inData1 = inData1 / 2;
++index;
}
//Bit array for inData2
char bitArr2[4] = { 0 };
int index1 = 0;
while (inData2)
{
bitArr2[(index1 / 8)] |= (inData2 %
2) << (index1 % 8);
inData2 = inData2 / 2;
++index1;
}
int hammingDistance = 0;
for (uint32_t i = 0; i < 32; i++)
{
char byte1 = (bitArr1[i / 8] &
(1 << (i % 8)));
char byte2 = (bitArr2[i / 8] &
(1 << (i % 8)));
if (byte1 != byte2)
{
++hammingDistance;
}
}
return hammingDistance;
}
//Main function with the variables, and to test the
functions.
//
//#include <stdio.h>
//#include "BitManipulations.h"
int main(int *argc, char **argv)
{
uint32_t Number;
uint32_t bitPosition;
uint32_t value;
int numOnes;
uint32_t input1 = 28;
uint32_t input2 = 24;
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("\nHamming Distance = %d \t number of Ones : %d\n", hDist, numOnes);
return 0;
}
OUTPUT:

Please complete the implementation of the four functions IN C. //************************************************************************************/ // // countNumberofOnes // //...
USE C Programming LANGUAGE ONLY PLEASE. We use <stdio.h> if that helps. For the following problems, create the prototype function, calling function “int main()”, and function. So the function prototype, function call, and function header/body should be seen in the answer. The processor directive is not needed. Show a sample call from the int main() function for all problems. If you can for the first one please show proof that it has no errors. 1. Write a function called DisplayColumbiaUniversity...
Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...
C++ Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a...
I need help with my homework please. I should write this program
in C++ language and use Inventory.h file (header file),
Inventory.cpp file (implementation file), and main.cpp file (main
program).
This is the program:
Demonstrate the class in a driver program. Input validation,
don’t accept negative values for item number, quantity, or
cost.
6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail store's inventory. The class should have the following private...
I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...
Edit, compile, and run the following programs on the UNIX shell: Write a program that takes in six commandline arguments and has four functions (described below) that use bitwise operators. The user should enter six space-separated commandline arguments: four characters (any ASCII character) followed by two integers. Anything else should print an error message telling the user what the correct input is and end the program. Convert the commandline input into "unsigned char" and "unsigned int" datatypes. Be careful with...
How would you answer this in visual studios c++ and text book
were using is Data Structures Using C++ Author: D.S. Malik. Please
help. It has to be written in .cpp
1) Sum of numbers Write a recursive function that accepts an integer argument and returns the sum of the number as an argument. For example, i 50 is passed as an argument, the function will return the sum of 1,2, 3, 4, 50. 2) Counting of times a character...
C Part 1 Given a structure that store the highest temperature (HighTemp) and the lowest temperature (LowTemp) of a day: typedef struct { char DayOfMonth[31]; /* e.g. “May 13”, “July 9” */ int HighTemp; /* the highest temperature of that day */ int LowTemp; /* the lowest temperature of that day */ } DayTemp; DayTemp Temperature[365]; Temperature is an array of structure DayTemp. Write a function that will return the average of HighTemp for a given number of days (NumberDay)...
In this assignment, you must complete the 5 functons below. Each function's body must consist of just a single C statement. Furthermore, the statement must not be a control statement, such as if, switch, or any kind of loop. For each problem, you are also restricted to the operators and constants as specified. */ /* 1. Write a function which zeros a variable x. A pointer to x is passed as a parameter. YOU MAY USE NO CONSTANTS in this...
Using C++ Write two `void` functions. These functions each take two integer parameters. The functions accomplish the following tasks. The first function prints out the numbers from the first argument up to and including the number passed as the second argument counting by the first argument (i.e. if the arguments are 2 and 10, the information below was given: #include <iostream> using namespace std; // function definitions// // main program int main() { int firstNumber,secondNumber; char countType, doAgain; // we will do this...