I want to develop a function in C that set a binary field in array starting from a given offset and finish with a given length.
For example, my binary array is:
01101011 10010101 11001011 11010001 11000101 00101011
the buffer used for set:
10011001 01011011 10100010
So if the offset = 5 and the length = 7, the result will be
we will set the 7 first bit from the set buffer (1001100
) in the binary buffer starting from the offset 5:
01101100 11000101 11001011 11010001 11000101 00101011
^ ^
| |__End of set field (len=7)
offset=5
Are there predefined algorithms for that? using bitwise operators?