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

C++ Bitset << operator not working. Pointer to bitset variable

I have a set of bitsets pointers in an unordered_map static unordered_map< size_t, bitset* > systemBits; And my function template static bitset & getBitFor() { size_t hash = typeid(system).hash_code(); …
Sidar
  • 504
  • 1
  • 9
  • 28
0
votes
1 answer

Member function returning bitset, inhert from base class

So I'm trying to create a base class for one of my projects that will have a couple classes inherit from it. My problem is I am trying to return a std::bitset from one of the methods, the problem is that in each of the sub classes will return…
csteifel
  • 2,854
  • 6
  • 35
  • 61
0
votes
2 answers

seeking a way to set a bitset of 128 bits or above in c++

I am using a big number (over 128 bits integer) in my code. I find that c++ have std::bitset to simple some operation so I don't have to break my data into several integers. But I soon find another issue, if I have to convert several (long) integers…
user1285419
  • 2,183
  • 7
  • 48
  • 70
0
votes
5 answers

Why not implement BitSet with a more size-deterministic type?

The Java reference here indicates that boolean types, while represented with a "bit" of information, do not have a precisely defined size. In contrast, other types seem to suggest that the size is defined. For example, an int is 32-bits, end of…
Kirby
  • 3,649
  • 3
  • 26
  • 28
-1
votes
1 answer

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 #include void print(const boost::dynamic_bitset<> bitset) { …
-1
votes
1 answer

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!
-1
votes
2 answers

How to find the 3rd bit of a number

I have a question with a problem in c++. I have to create a program where I have to create one variable from Int and to cout<< on the screen "True" if the 3rd bit is 1. My question is: How can I see what is the 3rd bit of that number; I've tried…
BerryTan
  • 11
  • 5
-1
votes
1 answer

c++ printing out incorrect binary after shifting << 32 times

The code below should be printing out 32 0s, then 011, then 0s till the 64 bit from right to left #include #include #include using namespace std; int main() { int a = 0b011; long long b = (a << 32); std::cout…
Astoach167
  • 91
  • 1
  • 7
-1
votes
2 answers

Bitset size inconsistency

so I'm initializing a Bitset variable with a length of 4. When i try to seed this Bitset with the Random's class nextBoolean method. It gives the effect of removing elements. This is more than likely my inexperience with using Bitset. But as far as…
carlos
  • 33
  • 1
  • 4
-1
votes
1 answer

what is the purpose of BitSet valueOf in fromString method

I would appreciate an explanation of what this line does exactly. BitSet.valueOf(new long[] { Long.parseLong(s, 2) }); While this code example posted by FauxFaus really helped me understand BitSet usage, I don't find the purpose of the above line…
learner101
  • 37
  • 3
-1
votes
3 answers

How to overload () operator for a class using boost::dynamic_bitset

I've created a class that simulates 2d set of data from a bitset. Here's what I've created so far: class Data { private: int width_; int height_; boost::dynamic_bitset<> * bitset_; dynamicznie public: …
user7419288
-1
votes
1 answer

Selecting Specific range bits from a bitset and displaying it

Given a particular bitset<32>, how do I select and display the m LSB bits of the bitset? m is an integer value. for example I have 10110111011110111101111011000100 and m = 8, the code should display 11000100. Thanks
-1
votes
1 answer

Java & MySQL: Store an Read a 365 position of bitarray. HOW?

I am currently working with Java and MySQL, and I found an issue I don't know how to solve. I have a class that stores a String of 365 positions that represents a Binary String "010111010010100...", and I would like to be able to store and read that…
-1
votes
2 answers

find greatest number, x for given y and n such that x ^ y <= n

I need to find a greatest number, x for given y and n such that x ^ y <= n Here n can be very large number - 1 <= n <= 10^10 and 1 <= y <= 10^5 for example : for y = 5 and n = 1024 x ^ 5, then x = 4 (4 ^ 5 = 1024) for y = 5 and n = 480 x ^ 5 ,…
Atul
  • 546
  • 4
  • 16
-1
votes
1 answer

Bit manipulation on uint64_t or std::bitset

I want to write a chess engine and I've decided to use the bitboard representation of the board. I've done some reading and I found out that the most efficient way to do it is to use 64-bit long variables and bit manipulation. However I also know…
Placeholder
  • 93
  • 1
  • 9