Question: How would I code the findLowBitC function so it will loop through the arrays and find which bit is set to 1 and return the
How would I code the findLowBitC function so it will loop through the arrays and find which bit is set to 1 and return the position to the function for the following code in C:
***As a side not I am using Keil to program this.
#include
uint32_t array0[] = {0x00000001,0x00000020,0x00000400,0x00008000,0x00440000,0x02200000,0x12000000,0x80000000}; // answer = 0
uint32_t array1[] = {0x00000000,0x00000020,0x00000400,0x00008000,0x00440000,0x02200000,0x12000000,0x80000000}; // answer = 37
uint32_t array2[] = {0x00000000,0x00000000,0x00000400,0x00008000,0x00440000,0x02200000,0x12000000,0x80000000}; // answer = 74
uint32_t array3[] = {0x00000000,0x00000000,0x00000000,0x00008000,0x00440000,0x02200000,0x12000000,0x80000000}; // answer = 111
uint32_t array4[] = {0x00000000,0x00000000,0x00000000,0x00000000,0x00440000,0x02200000,0x12000000,0x80000000}; // answer = 146
uint32_t array5[] = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x02200000,0x12000000,0x80000000}; // answer = 181
uint32_t array6[] = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x12000000,0x80000000}; // answer = 217
uint32_t array7[] = {0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x80000000}; // answer = 255
uint32_t *arrays[] = {array0, array1, array2, array3, array4, array5, array6, array7};
uint32_t narrays = sizeof(arrays)/sizeof(uint32_t*);
extern uint32_t findLowBitASM(uint32_t*);
uint32_t findLowBitC(uint32_t*);
int main(void){
int i;
volatile int position;
for (i = 0; i
{
//position = findLowBitASM(arrays[i]);
position = findLowBitC(arrays[i]);
}
while(1){position++;} // endless loop to keep micro from crashing
// position++ keeps position in scope for easier debugging
}
uint32_t findLowBitC(uint32_t* array)
{ }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
