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
8
votes
4 answers

Is there a builtin bitset that's similar to the std::bitset from C++?

I want to use a bit array in Python that I could use like the standard bitset from C++. Example: #include int main() { std::bitset<100> numBits; } However, I don't know if there is something similar in Python, preferably built-in.
starkshang
  • 8,228
  • 6
  • 41
  • 52
8
votes
1 answer

c++ How to sort a vector of bitsets?

I have a vector of bitsets: vector < bitset<1024> > myvector; What is the best way to sort this vector from: 0: xxx0100 1: xxx11002: xxx00103: xxx0001...... to this order: 0: xxx00011: xxx00102: xxx01003: xxx1100...... I already tried to do…
NPa
  • 83
  • 6
8
votes
6 answers

java.util.BitSet -- set() doesn't work as expected

Am I missing something painfully obvious? Or does just nobody in the world actually use java.util.BitSet? The following test fails: @Test public void testBitSet() throws Exception { BitSet b = new BitSet(); b.set(0, true); b.set(1,…
denishaskin
  • 3,305
  • 3
  • 24
  • 33
8
votes
2 answers

Bitwise memmove

What is the best way to implement a bitwise memmove? The method should take an additional destination and source bit-offset and the count should be in bits too. I saw that ARM provides a non-standard _membitmove, which does exactly what I need, but…
turbolent
  • 288
  • 1
  • 6
8
votes
2 answers

How can I increment std::bitset

How can I achieve an increment on a std::bitset<128> in C++? Because the bitset is 128 bits long, I cannot simply do std::bitset<128> set = std::bitset<128>(); set = std::bitset<128>(set.to_ulong() + 1ULL);
pvorb
  • 7,157
  • 7
  • 47
  • 74
7
votes
2 answers

Is it possible to create a vector of bitsets?

I am trying to create a vector of bitsets in C++. For this, I have tried the attempt as shown in the code snippet below: vector> bvc; while (true) { bitset<8> bstemp( (long) xtemp ); if (bstemp.count == y1) { …
uyetch
  • 2,150
  • 3
  • 28
  • 33
7
votes
4 answers

Bitset Reference

From http://www.cplusplus.com/reference/stl/bitset/: Because no such small elemental type exists in most C++ environments, the individual elements are accessed as special references which mimic bool elements. How, exactly, does this bit reference…
Maxpm
  • 24,113
  • 33
  • 111
  • 170
7
votes
0 answers

How to insert data into PostrgeSQL BIT VARYING column

In my Spring Boot application I need to store bit masks into a table column with the goal of performing bit-wise queries against that column. I have a domain class with a Long id field and a mask field containing the bit mask. I cannot figure out…
Michael Smolyak
  • 593
  • 2
  • 6
  • 21
7
votes
6 answers

"Cannot appear in a constant expression", I need this to be a variable, why won't it let me?

string convert_binary_to_hex(string binary_value, int number_of_bits) { bitset set(binary_value); ostringstream result; result << hex << set.to_ulong() << endl; return result.str(); } In the above method, I am…
NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
7
votes
6 answers

How to implement dynamic bitset in my specific code

I am using bitset and to improve the performance of my code I want to change it to dynamic bitset, but after reading some posts related to this, I still don't know the way to define my code. So I attached my code and I would like to know if any of…
thomas
  • 151
  • 1
  • 1
  • 9
7
votes
2 answers

Index structure for top-k queries on bitstrings

Given array of bitstrings (all of the same length) and query string Q find top-k most similar strings to Q, where similarity between strings A and B is defined as number of 1 in A and B, (operation and is applied bitwise). I think there is should…
Moonwalker
  • 2,180
  • 1
  • 29
  • 48
7
votes
3 answers

Get bits from byte

I have the following function: int GetGroup(unsigned bitResult, int iStartPos, int iNumOfBites) { return (bitResult >> (iStartPos + 1- iNumOfBites)) & ~(~0 << iNumOfBites); } The function returns group of bits from a byte. i.e if bitResult=102…
Evyatar Elmaliah
  • 634
  • 1
  • 8
  • 23
7
votes
2 answers

Large String of 1 and 0 to BitSet

I have a very large string ( 64 characters) containing 1s and 0s. sample - 1001111111101010011101101011100101001010111000101111011110001000 All I want is to convert it into BitSet var containing the 1s and 0s in same positions I am using the…
Jevin129
  • 81
  • 1
  • 4
7
votes
1 answer

C++ - Efficient way to generate random bitset with configurable mean "1s to 0s" ratio

I'm looking for a highly efficient way to generate random std::bitset of set length. I'd also like to be able to influence the probability of 1s appearing in the result, so if the probability value is set low enough, only a small percentage of all…
Kuba Orlik
  • 3,360
  • 6
  • 34
  • 49
7
votes
1 answer

Check if a bitset contains all values of another bitset

I'm trying to create an entity/component system that automatically matches suitable entities suitable systems. I'm using std::bitset and RTTI to automatically assign a bit value to every component type. A system is defined like this: MovementSystem…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416