bitset

Convert Byte Array into Bitset

I have a byte array generated by a random number generator. I want to put this into the STL bitset. Unfortunately, it looks like Bitset only supports the following constructors: A string of 1's and 0's like "10101011" An unsigned long. (my byte array will be longer) The only solution I can think of now is to read the byte array bit ...

How to write bitset data to a file?

I have a std::bitset that I'd like to write to a file, bit for bit, but of course fstream's write function doesn't support this. I can't think of another way besides converting each 8-bit group to a char using string and writing that... Anyone know of a good way? ...

Convert Bytes to bits

Hi, I'm working with java. I have a byte array (8 bits in each position of the array) and what I need to do is to put together 2 of the values of the array and get a value. I'll try to explain myself better; I'm extracting audio data from a audio file. This data is stored in a byte array. Each audio sample has a size of 16 bits. If t...

Trouble compiling a header file in VC++

I just reorganized the code for a project and now I'm getting errors I can't resolve. This header is included by a .cpp file trying to compile. #include "WinMain.h" #include "numDefs.h" #include <bitset> class Entity { public: Entity(); virtual ~Entity(); virtual bitset<MAX_SPRITE_PIXELS> getBitMask(); virtual void ge...

writing a BitSet to a file in java

I have a BitSet and want to write it to a file- I came across a solution to use a ObjectOutputStream using the writeObject method. I looked at the ObjectOutputStream in the java API and saw that you can write other things (byte, int, short etc) I tried to check out the class so I tried to write a byte to a file using the following code...

Best way to merge hex strings in c++? [heavily edited]

I have two hex strings, accompanied by masks, that I would like to merge into a single string value/mask pair. The strings may have bytes that overlap but after applying masks, no overlapping bits should contradict what the value of that bit must be, i.e. value1 = 0x0A mask1 = 0xFE and value2 = 0x0B, mask2 = 0x0F basically says that the...

Groovy on Grails: GORM and BitSets?

I don't see anything in the official documentation about unsupported persistence data types, so I'm working under the assumption that types available in the Groovy language should be handled. However, for the following domain class: class DocGroupPermissions { Workgroup workgroup; Document document; BitSet permissions = new BitSet(2) p...

Very Compact Bitarray in Java

I'm looking for a very compact way of storing a dense variable length bitarray in Java. Right now, I'm using BitSet, but it seems to use on average 1.5*n bits of storage space for a bit vector of size n. Typically, this isn't a problem, but in this case the bitarrays being stored are a pretty significant part the memory footprint of the ...

in bitset, can i use "to_ulong" for a specific range of bits?

hi im working on something that demands me to get access to specific/range of bits. i decided to use bitset because it is easy to get access to specific bits but can i extract a whole range of bits? ...

What is the most effective way to erase individual bits in a bitset? is it XOR or AND/NOT?

I have a large bitset that I want to frequently reset individual bits in it. Which method is faster? a) bitset[word_index] ^= 1 << bit_index or b) bitset[word_index] &= ~(1 << bit_index) The application is for the desktop (if that plays a role). ...

BitSet to and from integer/long

If I have an integer that I'd like to perform bit manipulation on, how can I load it into a java.util.BitSet? How can I convert it back to an int or long? I'm not so concerned about the size of the BitSet -- it will always be 32 or 64 bits long. I'd just like to use the set(), clear(), nextSetBit(), and nextClearBit() methods rather t...

How do I change the value of a dynamic_bitset?

I am using C++ boost's dynamic_bitset. I have already allocated a variable and I just want to change its value - to construct it anew from an 'unsigned long' like from the constructor, but I don't want to allocate the memory again or to create a temporary variable. What can I do? ...

I need to create a very large array of bits/boolean values. How would I do this in C/C++?

Is it even possible to create an array of bits with more than 100000000 elements? If it is, how would I go about doing this? I know that for a char array I can do this: char* array; array = (char*)malloc(100000000 * sizeof(char)); If I was to declare the array by char array[100000000] then I would get a segmentation fault, since the m...

bitset to dynamic bitset

Hi.. I have a function where i use bitset.Now i need to convert it to a dynamic bitset.. but i don't know how. Can somebody help me ? set<string> generateCandidates(set<string> ck,unsigned int k){ set<string> nk ; for (set<string>::const_iterator p = ck.begin( );p != ck.end( ); ++p){ for (set<string>::const_iterator q = ck.begin(...

Are Bitsets actually Bools?

In C++, are bitsets actually a set of bools? Doesn't this defeat the purpose of using a BitSet because bools are 32 bits (I think...)? ...

[C++] instantiating bitset using hex character.

Hey, I'm trying to figure out how to instantiate a 4 bit bitset based on a hex character. For instance, If I have a character with value 'F', I want to create a bitset of size 4 initialized to 1111 or if it is A, i want to initialize it to 1010. I could use a bunch of if statements like so: fn(char c) { bitset<4> temp; if(c == 'F')...

Output integral to ostringstream as binary?

I just realized that one can use bitset to output binary data to a stream based on the (fixed) size of the bitset. What's the least-extra-syntax way to output binary data to a stream using integrals? To show what I mean, here's a program and its output. I'd like the second line of output from this program to be identical to the first li...

java.util.BitSet -- set() doesn't work as expected

Am I missing something painfully obvious? Or does just nobody in the world actually use java.util.BitSet? The following test fails: @Test public void testBitSet() throws Exception { BitSet b = new BitSet(); b.set(0, true); b.set(1, false); assertEquals(2, b.length()); } It's really unclear to me why I don't end up wi...

how to represent an integer array using java.util.BitSet ?

I need to represent an array of integers using BitSet. Can somebody explain me the logic required to do this ? ...

Concatenate boost::dynamic_bitset or std::bitset

Hey, what is the best way to concatenate 2 bitsets? For example i've got boost::dynamic_bitset<> test1( std::string("1111") ); boost::dynamic_bitset<> test2( std::string("00") ); they should be concatenated into a thrid Bitset test3 which then holds 111100 Solutions should use boost::dynamic_bitset. If the solution works with st...