DO NOT USE: use bitset instead
Questions tagged [bitsets]
18 questions
73
votes
8 answers
boolean[] vs. BitSet: Which is more efficient?
What is more efficient in terms of memory and CPU usage — an array of booleans or a BitSet? Specific BitSet methods are not used, only get/set/clear (==, =, Arrays.fill respectively for an array).
Maxim
16
votes
4 answers
When to use STL bitsets instead of separate variables?
In what situation would it be more appropriate for me to use a bitset (STL container) to manage a set of flags rather than having them declared as a number of separate (bool) variables?
Will I get a significant performance gain if I used a bitset…

David
- 14,047
- 24
- 80
- 101
10
votes
3 answers
How to write a std::bitset template that works on 32 and 64-bit
Consider the following code
template void foo(std::bitset bs)
{ /* whatever */ }
int main()
{
bitset<8> bar;
foo(bar);
return 0;
}
g++ complains about this on 64 bit because the <8> gets interpreted as an unsigned…

Tyler McHenry
- 74,820
- 18
- 121
- 166
7
votes
1 answer
Setting boost dynamic_bitset from a string
Dynamic bitset
I have a use case where i need to populate
boost::dynamic_bitset , from a std::string buffer.
Can you suggest as to how to go about this. So I need to come up with a function
void populateBitSet (std::string &buffer,…

kal
- 28,545
- 49
- 129
- 149
5
votes
1 answer
BitSet memory usage in Scala
I would like to know what is the memory usage of BitSet in Scala.For example, if I do:
var bitArray:BitSet=new BitSet(10)
bitArray.add(0)
bitArray.add(2)
bitArray.add(4)
bitArray.add(6)
bitArray.add(8)
How does that compare with and…

Skuge
- 1,010
- 2
- 11
- 28
4
votes
4 answers
Easy way to convert a string of 0's and 1's into a character? Plain C
I'm doing a steganography project where I read in bytes from a ppm file and add the least significant bit to an array. So once 8 bytes are read in, I would have 8 bits in my array, which should equal some character in a hidden message. Is there an…

Anon
- 127
- 1
- 3
- 11
2
votes
5 answers
flag bitset, avoiding collisions, C
I've got a flag-holding integer that has an existing set of possible flags:
#define MAIL_ADDR_FROM 0x0001 /* address field contains the from address */
#define MAIL_ADDR_TO 0x0002 /* address field contains the to address */
#define MAIL_SEEN …

VMills
- 183
- 3
- 4
- 12
2
votes
1 answer
STL bitset problem
I have a template class "HEADER_FILE" that has a variable bitset<>
using std::bitset;
using std::bitset;
template class Foo{
bitset bits;
};
i cannot use
using namespace std;
in header…

Ashish Negi
- 5,193
- 8
- 51
- 95
2
votes
1 answer
Social graphs using bitsets
I came across the following line in an article where this internet technology firm talks about how they baked social features into their application:
Apache Thrift, Krati Data Store, JavaEWAH Compressed Bitmaps and JRuby
forms the part of our…

Varun Jain
- 1,901
- 7
- 33
- 66
2
votes
1 answer
Why a C++ bitset initialized using an string is reversed?
For the first time, I initialized a bit set using a string and found out that the bits are stored in reverse order, i.e.:
bitset<3> test(string("001"));
then the bits are stored as bellow:
test[0] = 1
test[1] = 0
test[2] = 0
I am not…

dahma
- 75
- 2
- 6
1
vote
2 answers
is it possible to convert bitset<8> to an array of characters of integers?
I have bitset<8> v8 and its value is something like "11001101", something in binary, how can we convert it to an array of characters or integers in c++?

bijlikamasla
- 371
- 3
- 6
- 11
1
vote
6 answers
How best to implement BCD as an exercise?
I'm a beginner (self-learning) programmer learning C++, and recently I decided to implement a binary-coded decimal (BCD) class as an exercise, and so I could handle very large numbers on Project Euler. I'd like to do it as basically as possible,…

Skilldrick
- 69,215
- 34
- 177
- 229
1
vote
1 answer
How do I change the value of a dynamic_bitset?
I am using C++ boost's dynamic_bitset.
I have already allocated a variable and I just want to change its value - to construct it anew from an 'unsigned long' like from the constructor, but I don't want to allocate the memory again or to create a…

R S
- 11,359
- 10
- 43
- 50
1
vote
1 answer
C++ convert 8 bit bitset to unsigned long, VS 2010 - not working
Below code works first two times thru and then on the third time the convert to ulong fails and gives me a 0XCF instead of 0xF3. Any idea what the problem is?? Seems like a bug in the VS 2010 to_long. binary '11110011' should convert to Hex F3! …

Duffy
- 9
- 1
1
vote
2 answers
Java multi-bit / compact small integer array
I am working on implementing some bloom filter variants, and a very useful data structure for this would be a compact multi-bit array; that is, an array where each element is a compact integer of around 4 bits.
Space efficiency is of the utmost…

Aniket Schneider
- 904
- 1
- 8
- 21