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
752
questions
0
votes
1
answer
48
views
Adding boost/dynamic_bitset using CPM Package Manager
I have been struggling with this for some time. I use CPM package manager to pull libraries from github for my project. I prefer it this way, instead of other linking methods. I also tried gh:boostorg/...
0
votes
1
answer
110
views
integer flags in system function calls
Here is an example for what I mean:
int open(const char *pathname, int flags);
and from the man page. Looking into Linux, it is obvious the flags are bit markers.
I am curious by the use of an int as ...
1
vote
4
answers
101
views
Java BitSet.size() is not returning the size I gave at the constructor
I have the following code:
private BitSet arrayListToBitSet(ArrayList<Boolean> code) {
// The problem is here, the bitset automatically is created using 64 bits even tho we are ...
1
vote
2
answers
254
views
Dealing with a pointer to a bitset in C++
I have a bunch of bitsets<32> as global variables in my program and I want to update them after passing a pointer to one of them to a function.
Here is an example:
#include<bits/stdc++.h>
...
2
votes
1
answer
210
views
Implementing Type SB riscv instruction in C
I am having some issues, I have made an attempt at decoding a 32 bit binary to a type SB instruction in RISCV Architecture set
I have shifted the opcode, imm, rs1,rs2 and rd values but have not ...
0
votes
0
answers
16
views
What is a BitSet and what is one used for? [duplicate]
I keep running into the concept of a BitSet, particualrly in the context of using one as an Entity ID in an ECS. I've not found a good explination for what one actually, how it works or why they in ...
0
votes
1
answer
95
views
Arduino SoftwareSerial wrong values
The wrong 1 byte values are being sent or received(I don't know) when using SoftwareSerial between Arduino leonardo and Arduino UNO.
UNO and Leo are connected via:
gnd
pin 9 and 8
here is the code ...
1
vote
0
answers
63
views
Storing List<Integer> into Redis as a bitmap
I want to store a List<Integer> into redis using the set command(instead of the setbit that I will have to do many times hence increasing the no of commandds).I want to use the bitmap way by ...
1
vote
0
answers
67
views
C++ how can I read runtime bitset parameter from file which I will use non-constexpr class
I have a problem and can not figure it out on my own. I am describing it and want you to give me ideas about it, please.
I need to define a bitset with dynamic size:
int x = fileparser.read("...
0
votes
1
answer
271
views
converting from BigInt to BitArray
what would be best way to convert object using rust from bigint (BigInt) to bits (BitArray<217>) also in reverse (example below)
using binary to decimal calculator I verified by hand that bigint ...
0
votes
0
answers
70
views
Persisting BloomFilterRedis
We use BloomFilter in a pretty busy flow computing environment with about 50K operations per second. Earlier, the filters were implemented on a per node basis and would periodically be cleared, to ...
4
votes
2
answers
77
views
Efficient equality test for bitstrings with arbitrary offsets
I have more than 1e7 sequences of tokens, where each token can only take one of four possible values.
In order to make this dataset fit into memory, I decided to encode each token in 2 bits, which ...
2
votes
1
answer
74
views
My VS 2022 doesn't handle over than 32 bit bitset
I am trying to convert 45 bit binary number into a hex number but when compiling, I get overflow error, but when applying the code on online C++ compiler, it works. My platform is X64. Any help please....
0
votes
1
answer
69
views
Bitset Intialization C++ [duplicate]
I know this initialization: bitset<20>.
But what does this initialization mean: bitset<1<<20>?
-1
votes
1
answer
35
views
Can't understand the behaviour of dynamic_bitset
I am working on a Hill Climber Algorithm and I need to represent data as bitsets.
To sumarize my issue, I have written this piece of code:
#include <iostream>
#include <boost/dynamic_bitset....
0
votes
3
answers
152
views
C++ bitset strange value [duplicate]
#include <bitset>
#include <assert.h>
#include <stdio.h>
using namespace std;
int main()
{
bitset<128> bs(42);
bs[11]=0;
bs[12]=1;
assert(bs[12]==1);
...
0
votes
2
answers
173
views
printing the bits of float
I know. I know. This question has been answered before, but I have a slightly different and a bit more specific question.
My goal is, as the title suggest, to cout the 32 bits sequence of a float.
And ...
2
votes
1
answer
301
views
std:bitset c++ external initialization
I want to wrap or cast a std:bitset over a given constant data arrary
or to formulate it differently, initialize a bitset with foreign data.
The user knows the index of the bit which he can check then ...
0
votes
1
answer
147
views
BitSet only grows with true bits and not false?
Currently with Java version "11.0.3" 2019-04-16 LTS on a Linux host (but would expect 8+ compatibility):
in the context of computing a picture in order to send a binary bitmap to some ...
2
votes
3
answers
90
views
How does BitSet's set method work with bits shifting to the left?
Java's BitSet class has a method Set that sets a single bit to 1 (=true). The method source code is as follows:
public void set(int bitIndex) {
if (bitIndex < 0)
throw new ...
-1
votes
1
answer
23
views
Better style to use bitwise vs comparison in certain cases?
Just wondering if it's better style/more efficient to write code like this:
if (bitset[index] & 1)
{
//do something
}
vs:
if (bitset[index] == 1)
{
//do something
}
Thanks!
4
votes
3
answers
610
views
Roaring bitmap using more storage than normal bitset
I have a bitset which i am using to track whether an item is present or not example
b = 01100110000
it represents that 2nd and 3rd items are present and 1st and 4th item are not present.
While ...
0
votes
0
answers
107
views
how to fast set the bitset by using multiple position once
how to fast set the bitset by using multiple position, eg: the position : 1,4,5,6,9,3. the bitset is 0101111001....,whether can use SIMD instruction?
I know the simple method, eg: assume the word_t is ...
0
votes
0
answers
118
views
Error 'std::out_of_range' what(): bitset::test in C++ 98
I have taken this code in comment from Question at this link .My objective is to store the unique values stored in single variable parameter
std::bitset<270> mem;
void getValue(int parameter)
{
...
0
votes
1
answer
362
views
How to increase heap memory size for Spock Framework?
The Java program runs fine but the test fails with the message:
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.BitSet.initWords(BitSet.java:167)
at java.base/...
0
votes
1
answer
141
views
What is the space complexity of bitset in this scenario
I am doing a leetcode problem where I have to find the duplicate of an array of size [1-N] inclusive and came upon this solution:
public int findDuplicate(int[] nums) {
BitSet bit = new ...
2
votes
0
answers
286
views
Is Serialized Roaring Bitmaps compressed?
According to the definition, roaring bitmap is a "better compressed bitset". Which means it is compressed by nature. But, according to my test, the size of Dgraph's Serialized Roaring ...
3
votes
4
answers
1k
views
What is the fastest way to get the lowest set bit of a C++ std::bitset?
I noticed that std::bitset does not have a function for returning or popping the lowest set bit of a bitset (nor the highest set bit for that matter). What is the fastest way to accomplish this task, ...
0
votes
1
answer
112
views
std::map<int, std::bitset<256 > > thread safety w/o mutex?
I have a
std::map<int, std::bitset<256 > > m;
After construction no new keys will be inserted and no keys will be removed. Can I safely assign the bitset in one thread while reading it in ...
0
votes
1
answer
145
views
Concatenate Bits from 3 characters, taken from different locations in the bitset
I am trying to concatenate the bits of 3 characters a, b and c into a bitset of 16 bits. The constraints are the following:
Concatenate the last 2 bits of a into newVal1
Concatenate the 8 bits of b ...
0
votes
2
answers
116
views
What is this "operator" block of code in c++ class
I'm using someone's class for bitmaps, which are ways of storing chess positions in 64-bit bitsets. I was wondering what the part with auto() operator does. Is "auto" used because it returns ...
0
votes
1
answer
23
views
Populating matrix by comparing 2 bits from 2 bitsets?
How to parse/read 2 bits at once from a bitset and process it?
I want to create a matrix that compares if 2 values match and populate the matrix with a 0 or 1.
This is what I did. This is for ...
4
votes
1
answer
206
views
BitSet.size() returns negative value. Known bug?
new BitSet(Integer.MAX_VALUE).size() reports a negative value:
import java.util.BitSet;
public class NegativeBitSetSize {
public static void main(String[] args) {
BitSet a;
a = ...
0
votes
1
answer
32
views
Algorithm : partial grid count problme
In partial grid count problem
Each point is marked with 1 or 0. In this case, the problem of finding the number of subgrid with 1 in all four corners
Each row is expressed in bitset form, and while ...
0
votes
1
answer
91
views
How I can convert a part of Hex String to Integer value in Java
I am going to implement a class in Java 11 to Convert a part of hex string like "8edb12aae312456e" to integer value. For example convert from bit 18 to 23 to integer value. I actually want a ...
1
vote
1
answer
139
views
Efficiently find ranges of consecutive non-set bits in BitSet
I'm trying to represent calendar available/unavailable slots for a particular day with each bit representing 15mins using BitSet. The bits which are set represent blocked calendar events. For getting ...
0
votes
1
answer
51
views
redis async replication of a bitset
I am using redis to store some pretty large bitsets. Redis is run in master/slave sentinel mode.
I got curious about the replication performance for very big bitsets (my bitset has a size of +-...
0
votes
1
answer
80
views
How to convert BitSet -> short array with 4 bit precision?
I want to convert the BitSet data of variable length to an array of shorts.
BitSet -> short[]
Every four bits of the bitset should be used to construct a new number.
Example data:
BitSet bits = new ...
0
votes
2
answers
246
views
How to convert short array to BitSet with 2 bit precision in Java?
I have a short array {0,2,3,1,…} which I would like to convert to a BitSet.
Expected bits in bitset: 00 10 11 01 …
Every two bit in the bitset should represent a short. (2-bit precision)
This should ...
0
votes
2
answers
667
views
Print out bitset quickly in c++
Im writing a program that outputs binary, and I got alot of it I want to output to the terminal, but this takes along time.
In other places in my program where I want to quickly output strings I use
...
1
vote
2
answers
1k
views
C++ - How to left/right circular shift a bitset?
Let's say I have a std::bitset<28> called left28.
I'm looking to left circular shift left28.
After doing some searching, I came across std::rotl (C++20) but it doesn't seem to play nice with ...
1
vote
1
answer
163
views
How does the cardinality work in Java BitSet?
import java.util.*;
public class Main {
public static void main(String[] args)
{
BitSet bs1 = new BitSet();
BitSet bs2 = new BitSet();
bs1.set(0);
bs1.set(1);
bs1.set(2);
bs1.set(4);
bs2.set(0);
...
0
votes
1
answer
578
views
Struct to bits c++
I am learning C++ and I wonder if it is possible to decompose a structure object into a sequence of bits?
// The task is this! I have a structure
struct test {
// It contains an array
private:
...
2
votes
2
answers
866
views
How to reduce the float rounding error when converting it into fixed-point in C++?
I have a float variable which is incremented 0.1 in each step. I want to convert it into 16-bit fixed value where it has 5-bits fractional part. In order to do that I have the code snippet below:
#...
0
votes
1
answer
488
views
How to flip all the bits in Java BitSet while preserving its length
How can I flip all the bits in a Java BitSet, while preserving its length?
For example, given the following BitSet:
BitSet.valueOf(new byte[] { 0b100111 })
// {0, 1, 2, 5}
Is there a simple method to ...
0
votes
1
answer
77
views
Can someone explain part *(int*) and how it have any relations to the bitset?
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
//from float to bits
float f;
cin >> f;
int x = *(int*)&f;
cout << x << &...
0
votes
1
answer
125
views
how to use itertools.combinations on a bitset (python)
I have a python integer that represents a bitset. How can I use itertools.combinations (or some other method) that will take an integer/bitset as input and produces all combinations of size k without ...
4
votes
1
answer
155
views
Generating all combinations of size 1 to n (bitsets)
There is a lot of quick methods on stack overflow that generate all the combination of bitsets of size k.
Ex:
combos(4,3) = {1110,1101,1011,0111}
However, is there a quick way to calculate all combos ...
1
vote
1
answer
374
views
How can I convert ANY user defined type to an std::bitset?
What I want to achieve is a means of converting any arbitrarily sized and formatted type to an std::bitset. Like this:
#include<bitset>
#include<bit>
#include<cstdlib>
#include&...
0
votes
1
answer
303
views
Using Python bitset to find all combinations of a set of size k
I am trying to speed up my own dynamic programming solution for Travelling Salesman. My original solution memoizes with a dictionary with a python frozenset() as part of the key. However, I believe ...