How to implement a bitset in C?

前端 未结 7 2139
-上瘾入骨i
-上瘾入骨i 2020-11-30 04:42

I have been using the Bitset class in Java and I would like to do something similar in C. I suppose I would have to do it manually as most stuff in C. What would be an effic

7条回答
  •  眼角桃花
    2020-11-30 05:03

    Well, byte bitset[] seems a little misleading, no?

    Use bit fields in a struct and then you can maintain a collection of these types (or use them otherwise as you see fit)

    struct packed_struct {
      unsigned int b1:1;
      unsigned int b2:1;
      unsigned int b3:1;
      unsigned int b4:1;
      /* etc. */
    } packed;
    

提交回复
热议问题