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
0
votes
1 answer

converting negative numbers in binary to decimal using bitset

#include #include #include #include using namespace std; int main(){ bitset<5> num(-5); if(num[0]) cout<<(num.to_ulong()-pow(2,5));// cout<<(num.to_ulong()-32); else …
billyjayan
  • 27
  • 8
0
votes
2 answers

std::string to std::bitset represented by std::string and vice-versa

Now-now this can be a little confusing but I can't come up with a more simple title that could tell exactly what I mean. I have a string that I wish to convert to binary (each char to 16bit width binary) STRING. And then the binary string back to…
Wrath
  • 673
  • 9
  • 32
0
votes
0 answers

divide information into bits bitset library

I am trying to get information from a file. The content of the file is unknown. I am opening the file using a fstream object and storing each piece of data into a unsigned char . The size however of a char is 8 bits. But I need to get the data into…
user3552926
  • 136
  • 3
0
votes
2 answers

C++: Registration of Global Variable Before Definition

I need a global variable in my C++ program. It is going to be a vector of bitsets. However, the size of the bitsets is determined at runtime by a function. So basically, I would like to register the variable (in the top part of my code) and later…
user1850980
  • 991
  • 1
  • 10
  • 15
0
votes
1 answer

bitset has no member ullong

I have tried to implement the following code, but I've got an error. Why is that? #include #include int main() { const std::string s = "0010111100011100011"; unsigned long long value = std::bitset<64>(s).to_ullong(); …
BeniMadhab
  • 29
  • 2
  • 10
0
votes
2 answers

How can I iterate a std::bitset in a circular fashion and return the index of the next 'true' bit?

I use a std::bitset to track what weapons a player has in a game engine. The player should be able to cycle through the available weapons in a circular fashion. i.e. If the player has the last weapon selected then pressing the next weapon button…
x-x
  • 7,287
  • 9
  • 51
  • 78
0
votes
1 answer

How to translate a string of zeros and ones into bitset?

So I have this code snippet to translate a string into bitset. String huffmancode = "0010110100"; char[] ch = huffmancode.toCharArray(); BitSet bs = new BitSet(); for (int i = 0; i < ch.length; i++) { if (ch[i] == '1') { …
JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132
0
votes
1 answer

Representing a multiset as a sequence of bits

We can use a bitmask to represent set presence in a finite (or at least indexed) domain efficiently, for instance to represent the letters in car we could represent this in a 26-bit set like…
dimo414
  • 47,227
  • 18
  • 148
  • 244
0
votes
1 answer

Generating sequential numbers using BitSet

I would like to store numbers, from 1 to N, sequentially in an array of BitSet. Is there an alternate solution apart from using the set() method on each number? Thanks!
Sid
  • 3
  • 2
0
votes
2 answers

clear all the multiples of a index in a bitset in Java?

I have a bitSet and I want to turn off all the multiples of a given index. eg: given a bitset -- > {1, 2, 3, 5, 7, 9, 11, 13, 15, 17}, I want to iterate through the bitset and turn off the multiples of each of them. In the end, I should have…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
0
votes
2 answers

Which datastructure to use in big values?

I am writting a programme in mapreduce. I need to save a big value for each key. In detail for each id(key), I want to save a value that consists of large numbers. I used numbers from 1 to 100000000. for example: id value 1 …
ali abdoli
  • 33
  • 6
0
votes
3 answers

BitSet(JAVA) is throwing outofBoundsException in the implementation of Sieve Of Eratosthenes

Here is my function for the implementation of Sieve Of Eratosthenes, void solve() throws IOException { int n = 200000; ArrayList primes = new ArrayList(); BitSet bs = new BitSet(n + 1); for(int i = 0; i <= n + 1;…
rishy
  • 1,559
  • 3
  • 14
  • 17
0
votes
1 answer

minimum set of binary vectors to get full coverage

I need to find an efficient algorithm that finds an optimal set of binary vectors in such a way that every index has a bit that is set in at least one vector in the set. Amusing motivation: I want to break into a castle and steal its treasure. In…
flyman
  • 210
  • 4
  • 15
0
votes
1 answer

is there a method to get the number of bits turned on in the BitSet in Java?

I want to get the number of bits turned on in a BitSet. here is a program to calculate even numbers. Ofcourse, there are easier ways to calculate even numbers, this is just for understanding of how to use BitSets. here is the code: Public class Test…
brain storm
  • 30,124
  • 69
  • 225
  • 393
0
votes
1 answer

Does PHP support long bit array?

So I'm trying to work on a web service that deals with long bit arrays (100+ bits). Can anyone suggest a class in PHP that deals with long bit arrays?
Tengyu Liu
  • 1,223
  • 2
  • 15
  • 36