Questions tagged [bitset]

A collection of bits organized as an array of bits, in which each bit can be accessed separately. For C++ bitsets, prefer the tag std-bitset

A collection of bits organized as an array of bits, in which each bit can be accessed separately.

Usage guidelines:

Related tags, with slighly differences:

751 questions
7
votes
2 answers

How do I create a bitset from binary string?

I have a binary string in a file that looks…
George L
  • 1,673
  • 2
  • 26
  • 39
7
votes
4 answers

writing a BitSet to a file in java

I have a BitSet and want to write it to a file- I came across a solution to use a ObjectOutputStream using the writeObject method. I looked at the ObjectOutputStream in the java API and saw that you can write other things (byte, int, short etc) I…
Avner
  • 215
  • 7
  • 13
7
votes
3 answers

Saving java BitSet to DB

Working with JPA, I would like to be able to save a BitSet to the DB and pull it back of course. Suppose I have: @Entity @Table(name = "myTable") public class MyClass { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) …
forhas
  • 11,551
  • 21
  • 77
  • 111
6
votes
1 answer

What's recommended practice for bitset manipulation?

I'm working on a machine simulation program. I've got a vector of bitsets for main memory, so that I may use a pointer to this vector, pMemory->at(i), to access any specific "word". I really do prefer the vector-of-bitsets design, and I'm sticking…
absterge
  • 63
  • 1
  • 3
6
votes
5 answers

Alternative to Java Bitset with array like performance?

I am looking for an alternative to Java Bitset implementation. I am implementing a high performance algorithm and seems like using a Bitset object is killing its performance. Any ideas?
rreyes1979
  • 1,855
  • 3
  • 23
  • 34
6
votes
5 answers

How can i convert bitset into short in c++?

if i have a bitset<16> bits(*iter) and a my short how i can assign this bist to my short? short myShort = ??bits?? It's possible to convert a bitset<16> to short?
Safari
  • 11,437
  • 24
  • 91
  • 191
6
votes
2 answers

efficient bitwise sum calculation

Is there an efficient way to calculate a bitwise sum of uint8_t buffers (assume number of buffers are <= 255, so that we can make the sum uint8)? Basically I want to know how many bits are set at the i'th position of each buffer. Ex: For 2…
n1r44
  • 581
  • 1
  • 4
  • 12
6
votes
2 answers

Remove leading zeroes from Binary converted from Decimal

I am solving a problem where I have to convert given first N natural numbers to binary numbers. I am using bitset and .to_string(). But, after the number is converted to binary it has some leading zeroes obviously as equal to the size of the given…
Arun Suryan
  • 1,615
  • 1
  • 9
  • 27
6
votes
3 answers

std::bitset::count vs __builtin_popcount

Comparing the following two expressions std::bitset<8>(5).count() __builtin_popcount(5) which one is better?
Milo Lu
  • 3,176
  • 3
  • 35
  • 46
6
votes
3 answers

How to build N bits variables in C++?

I am dealing with very large list of booleans in C++, around 2^N items of N booleans each. Because memory is critical in such situation, i.e. an exponential growth, I would like to build a N-bits long variable to store each element. For small N, for…
Clèm
  • 424
  • 3
  • 14
6
votes
7 answers

How does one store a vector or a bitset into a file, but bit-wise?

How to write bitset data to a file? The first answer doesn't answer the question correctly, since it takes 8 times more space than it should. How would you do it ? I really need it to save a lot of true/false values.
jokoon
  • 6,207
  • 11
  • 48
  • 85
6
votes
1 answer

std::bitset hash function algorithm

Does anybody know what algorithm thw hash function for bitset is using, this is from website : http://en.cppreference.com/w/cpp/utility/bitset/hash #include #include #include int main() { std::bitset<4> b1(1); …
JimBamFeng
  • 709
  • 1
  • 4
  • 20
6
votes
5 answers

Unordered (hash) map from bitset to bitset on boost

I want to use a cache, implemented by boost's unordered_map, from a dynamic_bitset to a dynamic_bitset. The problem, of course, is that there is no default hash function from the bitset. It doesn't seem to be like a conceptual problem, but I don't…
R S
  • 11,359
  • 10
  • 43
  • 50
6
votes
4 answers

What is the Time Complexity of Set operation of a BitSet in java?

I have a Scenario where I have to set a range of BitSet index to 1. So if I use /* *Code snippet */ BitSet myBitSet = new BitSet(100); myBitSet.set(10, 50); //************************** What would be the time complexity for…
Abhijit
  • 175
  • 5
  • 16
6
votes
1 answer

XOR 128 bit bitsets

I am trying to XOR tow 128 bit bitsets. #include #include int main() { std::bitset<128> testing; testing = std::bitset<128>(0x544F4E20776E69546F656E772020656F) ^ std::bitset<128>(0x5473206768204B20616D754674796E75); …
Pranav Kapoor
  • 1,171
  • 3
  • 13
  • 32