Questions tagged [std-bitset]

A C++ container class similar to an array but containing only bits, included in the library.

A C++ container class similar to an array but containing only bits, included in the <bitset> library. It has a fixed length specified at compile time via a template parameter.

It allows for random access and can be manipulated with standard logic operators.

A reference is available.

109 questions
0
votes
1 answer

How to Assign a bitset to an unsigned char vector?

I am using an unsigned char vector which has some hex values. std::vector sync; sync.push_back(0x50); sync.push_back(0x51); sync.push_back(0x52); sync.push_back(0x53); Then, using a bitset I "morph" the sync[3] to an…
siddyi
  • 23
  • 1
  • 7
0
votes
3 answers

Bitwise OR on Bitset giving wrong answer

#include using namespace std; int main(){ bitset<5> num=01000; bitset<5> n=00000; bitset<5> result; result=(n|num); cout<
Vikram
  • 41
  • 5
0
votes
1 answer

How to test std::bitset for randomness?

I create random bitsets with following code below. Now I wanna write some test and asking myself how to test the randomness of bitsets? Is there a good solution to this problem? As bitsets can not be represented as numbers AFAIK, I don't know hot to…
user1587451
  • 978
  • 3
  • 15
  • 30
0
votes
1 answer

sending bitset with MPI

What is an efficient way to send/receive bits from bitset class without conversion. Is it possible to use MPI_BYTE? If so, what to define as container for the array that is going to hold the bits? If this is not possible, which conversion is more…
JimBamFeng
  • 709
  • 1
  • 4
  • 20
0
votes
1 answer

Program crashes when using std::bitset but only when compiled with VC 2015

I'm working on a simple program which converts strings into binary code and back. I'm working on Ubuntu and wanted to compile the program on Windows with Visual Studio 2015. While the Linux build runs fine, on Windows it compiles, but crashes with…
HenrikS
  • 402
  • 3
  • 13
0
votes
1 answer

Bitset inside template declaration

I would like to know if it is possible to have bitset inside a template declaration like so: ListData>* hamming = new ListData>(); ListData is class containing a T element like so: template class ListData { …
Panos Filianos
  • 346
  • 1
  • 2
  • 18
0
votes
1 answer

Increase elements inside std::vector depending on std::bitset

I want to increase each element in a std::vector with length 256 by one, but depending on same position of a std::bitset<256> (if equal 1). Code below can be edited / compiled here. My question is, can I get away from the for loop and get in…
user1587451
  • 978
  • 3
  • 15
  • 30
0
votes
1 answer

convert dynamic_bitset to std::bitset

I have an application where I need to dynamically allocate a bitset at runtime, so I'm forced to use boost::dynamic_bitset. However, for efficiency reasons, I'd like to ultimately use the data as std::bitset. How might I go about converting from…
audiFanatic
  • 2,296
  • 8
  • 40
  • 56
0
votes
4 answers

Fastest way of counting occurences of 1's in multiple std::bitset?

I wanna count the occurences of 1 in multiple bitsets at same position. The count of each position is stored in a vector. E.g. b0 = 1011 b1 = 1110 b2 = 0110 ---- c = 2231 (1+1+0,0+1+1,1+1+1,1+0+0) I could do that easily with code below, but…
user1587451
  • 978
  • 3
  • 15
  • 30
0
votes
1 answer

Quickly converting a string in the format of '0 1 1 0 1' into a bitset

How can I quickly convert a string of ones and zeroes separated by spaces into a bitset? There exists a constructor to initialize a bitset from a string not separated by spaces, one to initialize a bitset to all zeroes or ones, and one to initialize…
noɥʇʎԀʎzɐɹƆ
  • 9,967
  • 2
  • 50
  • 67
0
votes
1 answer

bitset declration causes SIGSEGV

Here's the (incomplete) code to find some prime numbers. #include #include #include #define SQRT_10_POW_12 1000000llu #define _10_POW_12_BY_2 1000000000000llu/2llu using namespace std; int main() { unsigned int T; …
kesari
  • 536
  • 1
  • 6
  • 16
0
votes
5 answers

simple change of a character to its bit representation

Why am I getting an error? It looks pretty straightforward to me. Also, is this the best method for doing what I'm trying to do? #include #include int main() { char j = "J"; std::cout << bitchar(j); return 0; }…
-1
votes
2 answers

Initialization of a char from bit representation in C++

I have one message which contains a unique id, and some information I need to send through MPI processes. To do so, I convert this message to an array of bits. I convert one message to bit representation by using the std::bitset class. Now, I want…
-1
votes
1 answer

Best data structure for a sequence of digits [0:9]

What's the best data type that can handle a sequence of digits [0:9] in c++ with the least possible waste in memory? I think it may be something like that typedef bitset<4> Digit; vector myVector; but I think that each bitset<4> reserves a…
Muhammad Magdi
  • 150
  • 1
  • 10
-1
votes
1 answer

How to implement an array of bits in C++

I am trying to write a C++ template class which contains an array of bits (as a member variable). The size of the bit-array is known at compile time, so I'd really like it to be a std::bitset, but I'm having difficulty writing an operator[] function…
Harry
  • 884
  • 1
  • 8
  • 19