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

Java BitSet size larger then nbits set in Constructor

I am creating a BitSet with a fixed number of bits. In this case the length of my String holding the binary representation is 508 characters long. So I create BitSet the following way: BitSet bs = new BitSet(binary.length()); // binary.length() =…
Stefan
  • 2,603
  • 2
  • 33
  • 62
0
votes
1 answer

check the divisibility by 13 of a binary number

how to check if a binary number is divisible 13 if the user inputs the digits from the most significant to the least significant? the number of bits can be very large,so there is no point converting it into decimal and then checking its…
TSP1993
  • 183
  • 2
  • 12
0
votes
1 answer

reading bit values from bitset and transfering to byte array

I am working on building RTCM SC104 v3.1 messages for correction data of GNSS orbiters. A couple of fixed length messages I have had no trouble building once I figured out the data had to be sent MSB(most significant bit not byte) first. However for…
J Hinton
  • 147
  • 3
  • 13
0
votes
1 answer

no match for operator

I am trying to write a function that asks the user to input multiple hex strings to a console and then convert those strings to bitsets. I want the function to use pointers to the bitsets so that the bitsets are stored in the parent function. Due…
user2646276
0
votes
2 answers

Data structure recommendation

Developing in Java, I need a data structure to select N distinct random numbers between 0 and 999999 ? I want to be able to quickly allocate N numbers and make sure they don't repeat themselves. Main goal is not to use too much memory and still…
epeleg
  • 10,347
  • 17
  • 101
  • 151
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; }…
0
votes
1 answer

Java 1.7 Byte Array to BitSet not working

try { new BitSet(); byte[] packetData = new byte[receivePacket.getLength()]; packetData = receivePacket.getData(); bits = BitSet.valueOf(packetData); byte_header = Arrays.copyOfRange(packetData,0,12); …
Benjamin
  • 41
  • 5
0
votes
1 answer

Java Bitset error with large index

This is a follow up on the solutions in Find an integer not among four billion given ones since it's a old thread I created a new question. I wrote a bitset implementation assuming that the numbers are between java MAX_VALUE and MIN_VALUE integers.…
SidJ
  • 669
  • 12
  • 29
0
votes
1 answer

C++ two dimensional array of bitsets

I have an assignment where we're tackling the traveling salesman problem. I'm not going to lie, the part I'm doing right now I actually don't understand fully that they're asking, so sorry if I phrase this question weirdly. I sort of get it, but not…
0
votes
0 answers

Why is deviceID getting set to an empty string by the time I print it?

This one is driving me crazy: I defined these two functions to convert between bytes and int resp. bytes and bits: def bytes2int(bytes) : return int(bytes.encode('hex'), 16) def bytes2bits(bytes) : # returns the bits as a 8-zerofilled string …
tamasgal
  • 24,826
  • 18
  • 96
  • 135
0
votes
1 answer

BitSet initialized with byte[] returns unexpected bits

I'm writing a test for a bit reader class. I have a ByteBuffer that is the source for the reader and I initialize it with 32 random bytes. Then I create a BitBuffer with the ByteBuffer as initial. this is the byte[] I have: [-35, -15, 33, -71, -107,…
Kai
  • 2,145
  • 1
  • 20
  • 35
0
votes
2 answers

using map type creates gcc error: expected unqualified-id before ‘for’

I am new to linux, using terminal in Ubuntu virual box environment. I cannot figure out what and why these errors are happening, and they don't seem to match a missing ';' or #define conflict. Here are the errors I get from the gcc…
A S B
  • 11
  • 4
0
votes
3 answers

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…
user106740
  • 107
  • 1
  • 1
  • 8
0
votes
1 answer

Java BitSets writing to file

I am working on Huffman Compression algorithm. I have the code for each character. For example f=1100 d=111 e=1101 b=101 c=100 a=0 Now in order to achieve compression I need to write the codes as bits to a binary file. I am…
Maverick
  • 91
  • 3
  • 10
0
votes
2 answers

Converting boolean to BitSet in Java

So I before had this: public static final boolean opaqueCubeLookup = new boolean[4096]; But I found out that BitSet it much better at managing memory, so I changed it to this: public static final BitSet opaqueCubeLookup = new BitSet(4096); I also…
tambre
  • 4,625
  • 4
  • 42
  • 55