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
-2
votes
5 answers

Showing binary representation of floating point types in C++

Consider the following code for integral types: template std::string as_binary_string( T value ) { return std::bitset( value ).to_string(); } int main() { unsigned char a(2); char b(4); unsigned…
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
-2
votes
2 answers

How to convert int to binary and concatenate as char in C++

I have two values, 0 and 30, I need to store it's binary representation on one byte for each. Like: byte 0 = 00000000 byte 1 = 00011110 and then concatenate them on a string that will print the ASCII for 0 (NULL) and for 30 (Record Separator). So,…
バカです
  • 175
  • 2
  • 4
  • 18
-2
votes
1 answer

How BitSet admit long array with length 6?

BitSet internally uses long array of size 6. But it can contain 2^31-1 bits. long = 64 bit 6 longs = 64 * 6. But is much less than 2^31-1. Please explain this trick.
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
-2
votes
3 answers

How to count active bits in less then O(n)

I have a bitset of length n. say 0100010010 How ta claculate all its 1's not reading all the 0's (faster than in O(n))?
DuckQueen
  • 772
  • 10
  • 62
  • 134
-2
votes
1 answer

Manipulating bitset in C++

I was looking for some STL support for binary strings. bitset appears to be very useful, however I couldn't manipulate the individual bits sucessfully. #include #include using namespace std; int main() { string b =…
adrian008
  • 395
  • 6
  • 18
-2
votes
1 answer

Java 7 method not found in Android environment - BitSet

I am a developer new to Android en Eclipse (not to Java), using the latest ADT and Java SE 7u25. I am using a BitSet while working in the Android environment. In Java 7 there is the toByteArray method (toByteArray - Java 7 doc). However the method…
-3
votes
2 answers

Can this bitset generation be made better or more efficient?

Problem: Given an integer led as input, create a bitset (16 bits) with led bits set to 1. Then, create the following sequence (assume in this case led =…
Miguel Duran Diaz
  • 302
  • 1
  • 3
  • 12
-3
votes
2 answers

Why auto deduces a reference object instead of bool for std::bitset::operator []

I have the following code std::bitset<32> bs{21}; auto ref_obj = bs[0]; auto &another_ref = bs[0]; bool bool_obj = bs[0]; The type of ref_obj is not bool. But another_ref has the same type as ref_obj. std::bitset::operator[] has 3 overloads listed…
CS Pei
  • 10,869
  • 1
  • 27
  • 46
-3
votes
2 answers

Get octal value when n bits set

I want to create a method in C++ which will take a number as parameter. The method should return a number which represents an octal value for that number of bits set. Example: If I pass 4 as parameter then the function should return 17 because for…
Bhadresh
  • 15
  • 3
-3
votes
1 answer

can't create instance of bit-row

my class Row contains its data in a bitset. the class is implmented with templates, but it's not possible to create a new instance of Row object in my main-program. Row.h #ifndef ROW_H_ #define ROW_H_ #include template
user1882302
-3
votes
1 answer

How to check if a bit in a bitset is zero or one?

I have a bitset and I want to check whether a bit at a specific index is zero or one.
Soul Enrapturer
  • 367
  • 2
  • 3
  • 14
-4
votes
2 answers

binary sum through and HEX

I'm trying to build a simple BIN -> HEX converter using a class, I would like to save it later in a header file for eventual need <.<" . It kinda works. Kinda because I have some output, but I cannot understand what is happening when it prints X.…
mustache
  • 1
  • 2
-4
votes
4 answers

How to store data without using much space at c++

i am using c++, i need to store 6 boolean data without passing over 8 bits of space usage. And i need store them by using an array-like stuff ( vector, array, matrix etc. ). Some methods like vector uses much data than it's elements. I need to save…
Taha Sümer
  • 25
  • 11
-4
votes
2 answers

Segfault on C++ map iterator not out of bounds

I have the following code : iterator = u.U.begin(); //u.U is a map int sizeofIterator = u.U.size(); for ( int pp = 0; pp
-5
votes
1 answer

How to determine a bitset's length without numbers at C++

Is there any way to do something like this in C++: int a; bitset;
1 2 3
50
51