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

Accessing std::uint8_t as std::bitset

I would like to model a status register in C/C++, which should be accessible as std::bitset and as std::uint8_t. Thus I would combine them as union as follows: #include #include union byte { std::uint8_t uint; …
Phidelux
  • 2,043
  • 1
  • 32
  • 50
0
votes
2 answers

Save space writing bitset to a file in C++

I was wondering how I can save space writing a bitset to a file ( probably using iostream) in c++. Will breaking up the bitset into bitset of size 8 and then writing each individual bitset to the file save me space? What is your thought about…
DogDog
  • 4,820
  • 12
  • 44
  • 66
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
2 answers

Binary number from 0 to n having the same numbers of chars/

I want to make proggram wchich will be generete numbers in binary base from o to n, and i want thme all have the same numbers of chars. That's the code: #include #include #include #include #include…
0
votes
2 answers

Bitset Initializing in C++

class Address { private : unsigned char arr[4] = {0}; bitset<8> bits[4]; public : Address(){ char ip[50]; char temp[4]; cout <<"Enter your IP ADDRESS"; cin >>ip; …
Nagato
  • 87
  • 2
  • 8
0
votes
0 answers

Convert std::bitset to decimal std::string

I have a class for operations on numbers of N-bit lenght in which I use std::bitset for storing a number. I have to write a method for converting std::bitset to decimal string, so that the results of operations can be displayed to user. The problem…
vister
  • 31
  • 5
0
votes
0 answers

boolean[] vs. BitSet - indicies cached in Java?

I wanted to test which one is faster for my problem: boolean[] or BitSet. I need to update a seperate matrix for every pair of indices which are true. e.g. [true, true, false, true, false] results in [0][1]++, [0][3]++ and [1][3]++. Using…
0
votes
1 answer

Optimizing std::bitset with noexcept

I have some code which needs to check if a bit in a bit field is set. I've been impressed with how optimized std::bitset.count compiles down, so thought this would be a good use of it as well. I'm surprised that when I use bitset.test, the…
Brad
  • 5,492
  • 23
  • 34
0
votes
1 answer

Print values from BitSet with for loop

I want to print what I currently have with a single for loop (or another form of iteration) and only one flag declaration but I can't figure it out without using 'flag#' for each defined value. There should be 5 bits - which I have - but only one…
Squilly
  • 27
  • 1
  • 6
0
votes
0 answers

initiate bitset with an integer declared in my function in c++

I want to do int count=32; bitset(a); I have not put my entire code as it was irrelevant the basic thing is that I have to create a bitset of a given length and that length is calculated in the program. But this throws an error…
Ram Sharma
  • 59
  • 1
  • 2
  • 10
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
2 answers

Bitset consuming more memory

I have a list of Bitset having 25Million Bitset. Each Bitset I'm creating by using: Bitset.valueOf(new long[] {1}) The memory being consumed is around 1300MB. Ie: in an average its taking 52bytes. I'm not understanding why so much of memory is…
Shashank V C
  • 153
  • 1
  • 1
  • 9
0
votes
0 answers

how to convert negative number to binary and vice versa?

I have this audio file which I transformed it's audio values to binary numbers so that I hide them in image pixels. what I used to convert the audio values was bitset<16> since the audio values are stored in short int variables. the conversion to…
Allen
  • 3
  • 6
0
votes
1 answer

C++ Safety of enforcing alignment for 32 and 64 bit processors

I have two CPU's. One 32 bit and another 64 bit. We have a piece of C++ code like the following: typedef std::bitset<16> MyBits; typedef struct t_MyStruct_16 { uint32_t first; int16_t second; __attribute__((__aligned__(8))) MyBits st; }…
Yore
  • 384
  • 1
  • 4
  • 18
0
votes
1 answer

BitSet out of memory Java

I am using BitSet to keep track whether nodes in a Graph have been visited using DFS method. For this purpose I have created a BitSet[] array. The BitSets themselves can be between 100.000-500.000 entries. This is the code I am using. public…
HGO HGO
  • 37
  • 1
  • 6