Store binary values in an array in C [closed]
I wish to store some binary values in an array in C. How it can be done and how can i access any bit of a binary number.
Plz let me know if i i am unclear in posting the doubt.
Store your values in a normal array and write a simple function that would pick proper element and state of its bit, something like
int get_bit_from_array( unsigned char *A, int element, int bit ) {
return A[element] & ( 1 << bit ) ;
}
or even
int get_bit_from_array( unsigned char *A, int bit_absolute) {
int element = bit_absolute / 8;
int bit = bit_absolute % 8;
return A[element] & ( 1 << bit ) ;
}
精彩评论