Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a bitset in C?

Tags:

People also ask

What is BitSet in C?

Bitset represents a fixed-size sequence of N bits and stores values either 0 or 1. Zero means value is false or bit is unset and one means value is true or bit is set.

How is BitSet implemented in C++?

Let's implement bitset in C++, such that following operations can be performed in stated time complexities : init(int size): initializes a bitset of size number of 0 bits. void fix(int pos): Change the bit at position pos to 1.

How does a BitSet work?

Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through nbits-1 . All bits are initially false .

Is BitSet a data structure?

A bit array (also known as bit map, bit set, bit string, or bit vector) is an array data structure that compactly stores bits.


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 efficient way to implement?

byte bitset[]

maybe

bool bitset[]

?