Skip to main content

Questions tagged [bitwise]

Bitwise refers to a bitwise operation which operates on one or more bit patterns or binary numerals at the level of their individual bits.

10votes
4answers
1kviews

Linear version of std::bit_ceil that computes the smallest power of 2 that is no smaller than the input integer

I am not looking for feedback on the algorithm itself, but rather on the implementation; things like modern C++20 writing, style, proper ways to test and handle the validity of input (should I be ...
user1446642's user avatar
5votes
5answers
3kviews

Fast XOR of multiple integers

I need the bitwise XOR (exclusive-OR) of a list of integers (a function that is to ^ as sum is to ...
Watchduck's user avatar
7votes
2answers
255views

Bit manipulation to find a monochromatic clique on k vertices knowing all on k-1 vertices

I have a very hot segment of code in a large project. I've extracted the relevant segment and a toy example to illustrate it. The project involves an unavoidable combinatorial explosion related to ...
Dave's user avatar
  • 173
13votes
8answers
2kviews

Counting Occurrences of a Specific 3-Bit Pattern in a Byte Array

I was asked this problem in an interview, and this is the solution I came up with. I was told it's not the most efficient solution, but I can't think of any other solution. This is the problem. ...
Jacob's user avatar
6votes
2answers
97views

TypeScript Number Set

I originally premiered this code to the internet in this StackOverflow post, and per a recommendation through one of the comments, I am reposting it here. I am making a floating-point number set ...
Wasabi Thumbs's user avatar
2votes
0answers
62views

A machine learning model for predicting bit strings in Java

I have this GitHub repository (BitPredictor.java). Basically, I tried to harness a machine learning model for predicting bit strings. I have implemented it to the best of my understanding and have ...
coderodde's user avatar
5votes
1answer
250views

String character changes (case insensitive) - Go

I saw this question on one of the socials, presented as an Apple interview question. I have had to paraphrase as it was not given in text format. (Credit: Instagram @greghogg5) Given a string (S) ...
Romeo Lima's user avatar
2votes
0answers
88views

Implementing Generic, General, Specific and Portable Bitwise Operations

First my apologies. My mental faculties currently leave rather a lot to be desired and I have thus spend an inordinate amount of time on this pet project of mine, testing myself if you will. I find it ...
Zacariaz's user avatar
1vote
1answer
109views

Bit vector in Java supporting O(1) rank() and O(log n) select() - follow-up

(This post is the continuation of Bit vector in Java supporting O(1) rank() and O(log n) select(). It resides here (version 1.0.1).) Basically, I have implemented everything harold suggested, except ...
coderodde's user avatar
1vote
1answer
165views

Bit vector in Java supporting O(1) rank() and O(log n) select()

Introduction I have this GitHub repository (version 1.0.0.). It implements a rank(i) operation in \$\Theta(1)\$ time, and ...
coderodde's user avatar
3votes
2answers
140views

Unpacking a byte into 8 bytes, where the LSB of each byte corresponds to a bit of the original byte

I needed to unpack a byte into the LSBs of each byte in an 8-byte integer. After some testing, I derived a surprisingly efficient and elegant solution that uses magic numbers multiplication, though ...
CPlus's user avatar
  • 1,405
5votes
1answer
284views

Space efficient arrays

I needed a very space-efficient structure to store an array for which elements are unsigned integers with an upper bound known at runtime. I'm not an expert in pointer arithmetic, so I'm not sure if ...
fontanf's user avatar
5votes
2answers
2kviews

C Bit Utility Functions: Popcount, Trailing Zeros Count, Reverse All Bits

Here are some utility bitwise functions for 64 bit integers. I have independently derived inv64 (inverse all bits) and pcnt64 (...
CPlus's user avatar
  • 1,405
7votes
2answers
1kviews

Convert 64-bit Gray code to integer

This algorithm encodes a 64 bit integer. As input I have a 64 bit integer a, for example: (a is a single 64 bit number,which I split in 8 bytes for readability) <...
tutizeri's user avatar
2votes
1answer
76views

Finding the kth smallest number where all (hexadecimal) digits are different

I'm mostly trying to understand why the simpler char array mask below (to track which digits have been already used) is much ...
Shihab Shahriar Khan's user avatar

153050per page
close