开发者

Store binary values in an array in C [closed]

开发者_运维问答 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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 ) ;                 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜