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
1 answer

How to get the bitset back from a file saved as bytearrayoutputstream in java?

I created a BitSet called b and saved it to a file using this code snippet in java. byte[] bs = b.toByteArray(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(bs); FileOutputStream fr_out = new…
theprogrammer
  • 1,698
  • 7
  • 28
  • 48
0
votes
2 answers

Is it ok to use std::bitset in a struct that is written and read from disk?

I need to store bits in files and std::bitset would be perfect for this, because I need many of its operations when I read the structure back again. The class seems to consist of just an array of the bits and no other member data. So instead of…
Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
0
votes
2 answers

Calling constexpr function for bitset template parameter

I'm trying to type alias the std::bitset class where the template parameter N is calculated using a constexpr function. However, this approach seems to be running into a wall. The code currently looks like this: static constexpr std::size_t…
Geoffrey Tucker
  • 670
  • 1
  • 9
  • 18
0
votes
2 answers

how to store larger binary numbers in bitset (C++)

i m trying to make a program to convert a number into it's binary. Code: #include #include #include using namespace std; int main() { int a; string k; bitset n; …
Vaibhav
  • 6,620
  • 11
  • 47
  • 72
0
votes
2 answers

Signed int from bitset

How can I convert given bitset of a length N (where 0 < N < 64) to signed int. For instance, given: std::bitset<13> b("1111111101100"); I would like to get back the value -20, not 8172. My approach: int t = (static_cast(b.to_ullong())); if(t >…
carobnodrvo
  • 1,021
  • 1
  • 9
  • 32
0
votes
1 answer

BitSet is not working for Integer.MAX_VALUE and Integer.MIN_VALUE

I tried to use BitSet(java) to find the common numbers in two arrays. (It seems works very well on finding repeating chars), however, when I tried the corner case such as Integer.MAX_VALUE (it cannot show up in the res) and Integer.MIN_VALUE( it…
Clark
  • 1
  • 2
0
votes
1 answer

String Binary conversion

I'm currently writing a simple program to convert a string into base64 by manipulating its bit values. If I use the bitset function to convert a string into its bit values, how can I manipulate or store those values? For example, if I do…
0
votes
1 answer

bitset<4> converted to wrong value on Win7 Embedded

I have the following piece of code to convert from Sixbit ASCII to an ASCII string: std::string SixBitToASCII(char *buffer) { std::stringstream ss; std::stringstream out; for (int index = 0; index < 16; index++) …
Mendes
  • 17,489
  • 35
  • 150
  • 263
0
votes
1 answer

BitSet from byte[] with strange lenght

my code is : String blah = "blah"; byte[] blahBytes = blah.getBytes("US-ASCII"); System.out.println(Arrays.toString(blahBytes)); BitSet set = BitSet.valueOf(blahBytes); System.out.println(set.length()); the output is : [98, 108, 97, 104] 31 Why is…
mp3por
  • 1,796
  • 3
  • 23
  • 35
0
votes
1 answer

Bitset at the logic-gate level

I'm looking into implementing a 4-bit BitSet function at the logic gate level so that it can be written in structural Verilog--I have looked elsewhere for an answer to this question, but can only find C/C++ resources, which operate at a higher level…
Eli M.
  • 5
  • 4
0
votes
1 answer

Longest IPv6 prefix match

We are trying to implement a lngest prefix match of IPv6 addresses. What is the best way to represent IPv6 addresses to perform this computation (Longest Prefix match) efficiently. IPv6 addresses are usually represented in Array[Byte]. (IPv6…
user462455
  • 12,838
  • 18
  • 65
  • 96
0
votes
2 answers

support for BitSet in c11

I am porting some code written in Java to C11. The Java code uses BitSet to flip in flip bits in a vector. I know there is corresponding BitSet for c++, but I am not sure if there something similar available for c11. I have to use c11 per…
Andy
  • 2,469
  • 1
  • 25
  • 25
0
votes
1 answer

How would I use BitSet and a BufferedImage to quickly set pixels?

The Problem I'm trying to make a more efficient rendering system from scratch and I've come to the conclusion that using for loops are very inefficient for larger windows. Question So my question is, can I use BitSet to manipulate the pixels much…
Alec French
  • 61
  • 1
  • 6
0
votes
2 answers

What is the Java BitSet size after growing, shrinking and cloning its value?

Let be bs1 a BitSet in Java. The first bit is set bs1.set(0), then its size and length are 64 and 1 respectively. The 65th bit is set bs1.set(64), then its size and length are 128 and 65 respectively. Now, if I clear its 65th bit bs1.clear(64), its…
onlycparra
  • 607
  • 4
  • 22
0
votes
0 answers

Return the index of the first occurence the bit ‘pattern’ is found in num

Find_sequence (unsigned int num, unsigned int pattern) returns the index of the first occurence the bit ‘pattern’ is found in num. e.g. the bits in num = 10010 and pattern = 1001 should return 1 because the pattern was found at index 1 in num. Well…
max
  • 167
  • 2
  • 9