Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [bitset]

A bit array (also known as bitmap, bitset, bit string, or bit vector) is an array data structure that compactly stores bits. It can be used to implement a simple set data structure. A bit array is effective at exploiting bit-level parallelism in hardware to perform operations quickly. A typical bit array stores kw bits, where w is the number of bits in the unit of storage, such as a byte or word, and k is some nonnegative integer.

0
votes
1answer
38 views

Allocate Resource Effectively [closed]

I have module called printer allocator (PrinterAllocator) which will allocate the next available printer to the requester. ...
3
votes
2answers
57 views

Macros for bitsets / bit-flags in C

Context: I have some C code that uses a lot of bit-flags. The flag-sets may have a couple of hundred members. Currently these flags are defined as a 32-bit mask that must be applied to a specific ...
11
votes
2answers
170 views

C++ data type to store and manipulate individual bits

The use cases I’m facing require me to have a C++ data type that can store and manipulate the state of somewhere between 400 and 500 bits. In addition it is necessary to be able to store that state ...
0
votes
1answer
69 views

Find most significant bit without bitshifts

I am trying to find the most significant bit of unsigned number without using any bitshifts. This is what I have come up with, which looks very naive but it's very simple: ...
4
votes
3answers
1k views

Bitmasking and searching consecutive 1's

I have written code to count the continuous ones in an array or you can use binary string for convenience. Any solution using the binary string is acceptable. My Solution is: ...
10
votes
2answers
410 views

FlagSet with C++ templates

I am creating a C++ header-only library for FlagSet. A FlagSet is a container for booleans with meaning. Usually, it is done with constants (macro, enums, whatever), for example : ...
8
votes
1answer
277 views

Bitmask adapter

Today I had some time and tried to improve my own Bitmask adapter class. It's common practice to eliminate sets of boolean variables with something like a flag system. The old fashioned way was to ...
3
votes
3answers
702 views

Counting the number of 1 bits in a sorted bit array

I wrote a function in python to count the number of 1-bits in a sorted bit array. I'm basically using binary search but the code seems unnecessarily long and awkward. I did test it for several ...
1
vote
1answer
184 views

Simple bitset in Go

I was playing with an implemention of sieve of Eratosthenes in Go and realised a memory-efficient solution would benefit from a memory-efficient data structure for storing boolean values at the given ...
4
votes
1answer
368 views

Type-safe flag sets (bit fields) that make sense

All solutions to flag sets that I've come across are sets of integers representing individual bits (often preprocessor constants or enums). What has always bothered ...
6
votes
1answer
389 views

Creating and storing binary arrays

I recently created a library in C, which creates and stores binary arrays. My library uses the standard fixed data types and allocates no more than 8 bytes for a binary array (8 bytes = 64-bit ...
11
votes
2answers
4k views

Bit array implementation

I have made a bit array implementation that can be seen below: ...
6
votes
1answer
134 views

Representing integers as a sequence of bits

Here is a class Bits that I wrote in order to deal with sequences of bits that also need to be interpreted as non-negative integers (in case you are familiar with ...
0
votes
1answer
72 views

Adding bits, simpler

Considering that two bitsets are provided in the form of strings, char a[] and char b[], as in the code below. And the task of ...
1
vote
1answer
109 views

Performance issue when dealing with bits [closed]

Here is the slow part of my code ...
2
votes
1answer
629 views

Jolly jumpers programming challenge

I have posted my solution to the jolly jumpers programming challenge(detailed here) for your review: A sequence of n > 0 integers is called a jolly jumper if the absolute values of the ...
10
votes
1answer
3k views

Bit shifting and masking

I was wondering if someone could review this simple bit of code that originally was in C++, but now converted to C# as practice in using bit-shifting and creating a sort of a quasi-array functionality....
7
votes
1answer
655 views

A rusty Bit Vector library

As an exercise to learn Rust I've decided to write a Bit Vector library, furthermore I also intend to use it later because my version can share slices of the bit vector between threads whereas the ...
10
votes
2answers
709 views

Naive parallel Sieve of Eratosthenes in Java

My naive version now is too slow. I think setting/accessing concurrent atomic bit is way slower compared to access/modify an array of boolean. Second, the parallel execution only happens on the ...
6
votes
1answer
418 views

Bit string builder for Java

I have this Java class for building bit strings. The set of methods it provides resembles that of java.lang.StringBuilder. See what I have: BitStringBuilder.java: ...
7
votes
1answer
530 views

Genetic algorithm to find the maximum binary number of a given length

I have written some codes in java implementing simplest genetic algorithm. The code finds (or rather tries to) the maximum value possible for a user-defined number of bits. For example, for 16 bit ...
0
votes
2answers
64 views

Create an array with at least a given number of bits

I use this declaration for an array which must contain a bit for every minute in a day: ...
3
votes
0answers
132 views

ACM-ICPC HackerRank challenge in C++

I was doing a programming question in C++ at HackerRank. Given a set of up to 500 bitstrings, each up to 500 bits long, the task is to find the pair a and b such that the bitwise OR contains the most ...
1
vote
1answer
42 views

Create a collection of binaries with random set positions

I would like to create a collection of binaries with n set bits and total length should be between n and 31; also those set bits ...
2
votes
2answers
71 views

Implementing bounds-checking with exceptions based on an existing bitset container

BitPat here is a wrapper around a bitset. ...
8
votes
3answers
2k views
4
votes
0answers
280 views

Sieve32FastV2 - A fast parallel Sieve of Eratosthenes

I’ve created a much cleaner, better designed version to my parallel sieve. I’ve implemented most of EBrown’s micro-optimizations but also revamped the code on my own (that is not in direct response ...
8
votes
1answer
760 views

Sieve32Fast - A very fast, memory efficient, multi-threaded Sieve of Eratosthenes

An improved version Sieve32FastV2 is available. The classical solutions for the Sieve of Eratosthenes fall into 2 camps: one uses a bool[], which is fast but very ...
5
votes
2answers
133 views

BitSet wrapper to act as a sieve abstraction

This is a BitSet wrapper class to act as a Sieve abstraction for a prime calculator. Review for performance and Java/Java 8/Guava best practices. ...
13
votes
1answer
2k views

C++ FlagSet: typesafe usage of enumeration as bitset/bitmask

Below is my attempt at providing a type-safe way to combine enumeration and bitset together. The resulting class is intended to be use as a set of flags, where each flag is a member of the "user-...
6
votes
3answers
6k views

C++ bitset implementation

What are the issues/better ways to do this? I was just trying to implement this for practice and learn C++. Can anyone suggest efficient implementations of other functions such as count, size, all, ...
7
votes
2answers
524 views

Scala BitSet implemented with Java BitSet, for use in Scala Enumerations to replace ValueSet

Due to a performance profiling hotspot detailed here, I implemented my own BitSet using Java's BitSet. This is intended to ...
5
votes
0answers
159 views

Easy bitset IO v2

In a previous question I posted a method for easy std::bitset IO on a bit-for-bit basis. This question was later followed up in another solution. Both of these ...
12
votes
1answer
286 views

Easy Bit IO. Very simple interface works up to N == 64

After reading this question Easy bitset I/O. I wanted to see if there was a simpler way of doing it. This is how I would define a way of outputting ...
5
votes
2answers
2k views

Easy bitset I/O

I'm writing a program that makes heavy use of std::bitset's and occasionally needs to read/write these to file. std::bitset does ...
8
votes
2answers
1k views

Sorting a set of numbers in a file using Java BitSet

I have implemented a program to sort a file consisting of numbers. The program generates a different output file with all numbers sorted in it. I have implemented this program using ...