0
votes

I do not have much expertise in bit operation as I am beginner. Can you help me or give me any clue! how to do this in C programming!- This function fetches bits from a byte array, which contains suitable number of bytes to cover the largest bit index in bit_idxs array. It assumes that the bytes in the array are composed as follows:

  • if array = {0xA3, 0x58}, it assumes a number 0xA358 = 1010 0011 0101 1000, and assigns bit index 0 as the left most bit. if bit_idxs = {0, 2, 10} and n = 3, it fetch 1010 0011 0101 1000 ^ ^ ^ 1, 1, 0 since bit 0 is 1, bit 2 is 1, and bit 10 is 0. Then, it sums these bit values, which is 2. Before returning the sum,it clears the bits that are set, that is, it clears bit 0 and bit 2 so that the array becomes 0000 0011 0101 1000 ^ ^ ^ array = {0x03, 0x58}.
So you need to take the index, and calculate from it two other indices - one, is for the byte within the array which is containing the bit, and the other one is for the bit number within this byte. Can you do that? - Eugene Sh.
Hint: just do 1 bit at a time. If bit_idx = {0, 2, 10} then you can do bit_idx=0, bit_idx=2, and bit_idx=10, each separately. - user253751