We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Dear all, I want to access some continus bit,let me can modify the value,such as, for(i = 0 ; i < 10 ; i++) { bit[i] = ?; } but you know,the bit var cann't build as a array in keil c51,but build some boolean var with byte will speed down the MCU and more code,Who can give me a good advice and a way,Thanks in advance.
The thing you're looking for doesn't exist, in that form, because the MCU can't do it either. So use masking and shifting on whole bytes. You may want to write your own little assembly functions or C macros to handle it.
Hi, I think you could do something like this:-
#define noOfBits 10 /*required 'no of bits' in bit array */ char bitNumber = 3; /* bit to access/test */ char bArray[(noOfBits + 7)/8]; /* allocate enough space to store all bits */ bArray[bitNumber/8] |= 1 << (bitNumber % 8); /* set bit */ bArray[bitNumber/8] &= ~(1 << (bitNumber % 8)) /* reset bit */ if (bArray[bitNumber/8] & (1 << (bitNumber % 8)) /* test bit none zero */