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
0 answers

arithmetic operations with std::bitset in C++

I'm here today to ask you some wise hints on how I can handle big std::bitset the right way. Specifically, I have to manage bitset as large as 256 bits (even more eventually), and until I need to perform classical binary operations, I'm not in…
panc_fab
  • 522
  • 1
  • 7
  • 24
0
votes
1 answer

C++ primer 5th edition: A bitset to represent a sequence of integers

I am asked on C++ primer 5th edition this exercise: Exercise 17.10: Using the sequence 1, 2, 3, 5, 8, 13, 21, initialize a bitset that has a 1 bit in each position corresponding to a number in this sequence. Default initialize another bitset and…
Maestro
  • 2,512
  • 9
  • 24
0
votes
2 answers

How do I flip part of number/bitset in C++ efficiently?

Consider I have a number 100101 of length 6. I wish to flip bits starting from position 2 to 5 so my answer will be 111011. I know that I can flip individual bits in a loop. But is there an efficient way of doing this without a for loop?
Leena
  • 703
  • 1
  • 12
  • 21
0
votes
1 answer

Expose a private std::bitset field that is inside a class for modification

I'm coding in a C++ project that hasn't advanced beyond C++11 yet. Let's say I have an enum class as follows: enum class Weekdays { kSunday = 0, kMonday, ... kSaturday, }; I want to create a class that has a private std::bitset…
0
votes
1 answer

Linux API read/write and c++ bitset

How to use C++ bitset container with Linux API read/write functions? Something like this: #include #include #include // Linux API open #include // Linux API read,write,close using namespace std; int…
Blademoon
  • 109
  • 1
  • 8
0
votes
1 answer

A general question about possible future C++ language or standard library features regarding bit streams

Is there any mentioning of having a specific bitstream object either in a future release of C++ beyond C++20 or within the standard library? For example; we can have an std::bitset object where n is a constant known integral value. Pseudo…
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
0
votes
1 answer

Using std::bitset to count subsets of a finite set

I would like to check how many subsets S of the set [1, ..., 15] there are so that it is impossible to choose two elements from S such that their sum is a multiple of 3. The algorithm to check this is as follows: there is a natural bijection…
J. D.
  • 279
  • 1
  • 9
0
votes
1 answer

Float to 4 uint8_t and display

I read from float in Wikipedia and i tried print his bits. i used std::bitset and this return other bits different from what I expected(i know because i used the same number of the example in the link), then i used memcpy() and copy the memory of…
Pipe Soto
  • 320
  • 2
  • 9
0
votes
1 answer

C++ bitset reference

Two questions on bitset reference: Q1. Is there any way we can return a class private member bitset? In the code snippet below (followed by output), I experimented with the regular reference but it won't even modify the bitset member in Foo class.…
ZR_xdhp
  • 361
  • 2
  • 13
0
votes
0 answers

Bitset as an constructor argument

I have a problem with understanding of std::bitset. I want to use bitset as a switch for mutliple functions. Imagine class A and function Func1. Constructor looks like this A(bool procFunc). Usage is simple. If I want to use Func1 i will pass…
AxelF93
  • 43
  • 5
0
votes
2 answers

Read large Base-10 number of arbitrary size into bitset

I want to read a base10 number from a string or stdin into a bitset. Is there any std function to do this, or do I have to implement it myself? Example: bitset<4> buffer; cin >> buffer; cout << buffer; Input: 5 Output: 0101 Note: I need to support…
user5182794
0
votes
0 answers

std::bitset set function throwing error (procedure entry point could not be found)

I'm learning C++ using the learncpp website, i'm on Windows 64bits and i'm using GCC with C++14. I tried to implement the example in the std::bitset parts of this chapter : http://www.learncpp.com/cpp-tutorial/3-8a-bit-flags-and-bit-masks/ No error…
Alvin FREY
  • 43
  • 11
0
votes
1 answer

Memory Conservation with Manual Bit Fields vs. std::bitset

I'm learning about bit flags and creating bit fields manually using bit-wise operators. I then came across bitsets, seemingly an easier and cleaner way of storing a field of bits. I understand the value of using bit fields as far as minimizing…
Logan West
  • 45
  • 6
0
votes
0 answers

Modify integer from bitset

I've been using the bitset the following way: unsigned long value = 0; bitset myBitset(value); // do something with the bitset value = myBitset.to_ulong(); Is there a way to avoid using the last line and affect the value's bits from the…
Dan
  • 59
  • 7
0
votes
1 answer

C++ Accessing bitset<8> two bits at a time

I have a vector of bitset<8> that looks like this: 01010110 01010111 01011000 etc.. How can I access the bits two at a time? How can I store two bits in a variable? For the first element of the vector I want 01, then 01, then 01, then 10 and so on..
Gus
  • 43
  • 7