Binary operations in C Implement a function that fetches bits from a byte array, of which bit indexes are stated in bit_

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Binary operations in C Implement a function that fetches bits from a byte array, of which bit indexes are stated in bit_

Post by answerhappygod »

Binary operations in C
Implement a function that fetches bits from a byte array, of which
bit indexes are stated in bit_idxs array containing n elements. It
returns the sum of these bits after clearing the bits that are set
(value 1).
CODE TEMPLATE:
unsigned int fetch_bits_sum_and_clear(unsigned char* array,
unsigned int* bit_idxs, unsigned int n) {
return 0;
}
TIPS:
brief Fetches bits from a byte array, of which bit indexes are
stated in
* bit_idxs array containing n
elements. It returns the sum of these
* bits after clearing the bits that are
set.
*
* \details 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 fetches
* 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}.
*
* \param array The byte array which has suitable number of
elements to cover
* the largest
value in bit_idxs array.
* \param bit_idxs The array of bit indexes, which has n
elements in it.
* \param n The number of elements in bit_idxs
array.
* \return The sum of fetched bit values.
*
* \note In your implementation, do not write to stdout to
check the functionality.
* You should use my_tests function to
print and check the functionality
* of your implementation.
Binary Operations In C Implement A Function That Fetches Bits From A Byte Array Of Which Bit Indexes Are Stated In Bit 1
Binary Operations In C Implement A Function That Fetches Bits From A Byte Array Of Which Bit Indexes Are Stated In Bit 1 (81.08 KiB) Viewed 37 times
Binary operations in C Implement a function that fetches bits from a byte array, of which bit indexes are stated in bit_idxs array containing n elements. It returns the sum of these bits after clearing the bits that are set (value 1). The 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[] = {OXA3, 0X58}, it assumes a number OxA358 = 1010 0011 0101 1000, and assigns index 0 to the left most bit. If bit_idxs[] = {0, 2, 10) and n = 3, it fetches 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 Λ Λ A array[] = {OxO3, Ox58}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply