/*
* bitSum8bit - returns count of number of 1's in a byte
* Examples: bitSum8bit(257) = 2, bitSum8bit(7) = 3
* Legal ops: & ( ) >> +
* Do not use a loop!
*/
int bitSum8bit(int input)
{
// These are all lines of code that you need.
int mask = ;
int quarterSum = ;
int mask2 = ;
int halfSum = ;
int mask3 = ;
return ;
}
// C program to return count of number of 1's in a byte
#include <stdio.h>
int num_to_bits[16] = {
0, 1, 1, 2, 1, 2, 2, 3,1, 2, 2, 3, 2, 3, 3, 4
};
/* Recursively get nibble of a given number
and map them in the array */
unsigned int bitSum8bit(unsigned int input)
{
int nibble = 0;
if (0 == input)
return num_to_bits[0];
// Find last nibble
nibble = input & 0xf;
// Use pre-stored values to find count
// in last nibble plus recursively add
// remaining nibbles.
return num_to_bits[nibble] + bitSum8bit(input >> 4);
}
int main()
{
int input = 257;
printf("%d\n", bitSum8bit(input));
}
Get Answers For Free
Most questions answered within 1 hours.