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

java switch statement not ignoring the cases not listed

I want to ignore all other characters besides A, G, T, C, but when I put N at the end of the string, it prints out 00. the output should be 00 0101 1010 1111, but it is 00 0101 1010 1111 00. I used the default case in the switch statement because I…
l.bol
  • 7
  • 8
-1
votes
3 answers

Find a block of continuous set/unset bits

I am looking for a way to find a continuous block of set or unset bits in a bitset, for example in the bitset 01010111010 if i am looking for 3 set bits, i want to get 6 as result (counting from 1, would be 5 if i'd count from 0). Also, this is for…
tkausl
  • 13,686
  • 2
  • 33
  • 50
-1
votes
1 answer

array of std::bitset as a return value

I need to write a function to do N different Boolean operators on two std::bitset which in each run program can have different size. so I tried to write a function that do the operation inside and return array of bitset but I don't know how should I…
Am1rr3zA
  • 7,115
  • 18
  • 83
  • 125
-1
votes
1 answer

No viable overloaded operator[] for type 'vector>' c++

I keep getting the error: No viable overloaded operator[] for type 'vector>' I am trying to execute something while this hex value is not contained within my vector. I guess the error has something to do with the way I am trying to check…
David
  • 501
  • 3
  • 10
  • 30
-1
votes
1 answer

c++ how to make vector store bitsets?

So basically I want to store std::bitset<128> within std::vector<>. I have tried this: std::vector> myVector; But compiler complains about invalid template parameters. How can I fix this and can I add this type into a typedef for…
The amateur programmer
  • 1,238
  • 3
  • 18
  • 38
-1
votes
1 answer

Set a random additional bit in bitstring

Given a bitstring s, I am looking for a method that will set a random 0 bit in s to a 1 bit. Furthermore, the user should be able to specify how far "left" in s a bit may be set. For bonus points, the solution should still terminate if all bits are…
Jon Gjengset
  • 4,078
  • 3
  • 30
  • 43
-1
votes
1 answer

Solving variation of sum-subset puzzle using bitset

i came across alternate way of solving sum-suset problem using bitset. Here is the link for the solution :- variation of sum-subset problem solution link Problem description is given in below link :- Problem statement Unfortunately i am not able to…
user1057741
  • 265
  • 1
  • 2
  • 10
-1
votes
2 answers

Java : Difference between a boolean array & BitSet?

Java : Difference between a boolean array & BitSet? As per the documentation of BitSet, "This class implements a vector of bits that grows as needed. Each component of the bit set has a boolean value." This makes me think, what is the difference…
Rajesh Pantula
  • 10,061
  • 9
  • 43
  • 52
-1
votes
2 answers

Accessing Bitset present inside a struct C++

I have a structure that looks like this : struct bf_t { bitset<250000> h0; }; I want to know how to allocate memory for this struct and how to access h0 in my main() . I tried doing this: bf_t *b; b->h0.set(1); error: base operand of ‘->’ is not…
premprakash
  • 1,505
  • 3
  • 18
  • 27
-1
votes
1 answer

C++: Program does not seem to work when bitset arrays are used (correctly!) in place of bitset variables

I have a very peculiar issue debugging some code. In the first iteration of this program, I used several bitset variables as opposed to making a single bitset array. I am trying to figure out why the array only works for the very first case of…
Louis93
  • 3,843
  • 8
  • 48
  • 94
-1
votes
1 answer

Is possible to reinitialize bitset from STL with string?

Is it possible to reinitialize bitset with string? I have a simple class like this: class Bits{ public: bitset<1024>b; }; Is it possible that later I get a string and in code I set bits with the string (string is 1024 length and only 1 and…
Damir
  • 54,277
  • 94
  • 246
  • 365
-2
votes
1 answer

c++ Include in linux, and gcc raises error which occurs within ?

I try to use bitset in my c++ code, the desired behavior is my code man pass compiling and use bitset correctly. The specific problem is while compiling gcc raise this: g++ -g -Wall -Wshadow -I../bin -I../filesys -I../userprog -I../threads…
pkutp
  • 11
  • 2
-2
votes
1 answer

Several questions about constructors of std::bitset?

From cppreference #3 template< class CharT, class Traits, class Alloc > explicit bitset( const std::basic_string& str, typename std::basic_string::size_type pos = 0, typename…
Kian Lee
  • 9
  • 3
-2
votes
3 answers

What is "expected unqualified-id" error in C++?

Im trying to learn stl:bitmap, but I'm getting the following error: Headers added - bitset - string Ive searched other SO posts for this error, but they are not related to bitset. My Code int main(){ bitset bs; bitset<10> bs2(45); …
Amit Kumar
  • 804
  • 2
  • 11
  • 16
-2
votes
5 answers

Why is the bitset function not returning correct decimal value for binary strings like 1110 or 1011?

Here is my code that takes a 4 character string of 1's and 0's and converts to decimal using bitset function. It is returning correct values for all combinations except those involving 11's and 10's like {1110,1010,1011,1111}. For these numbers its…
Midhun
  • 744
  • 2
  • 15
  • 31