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.

5 votes
2 answers
79 views

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
1 vote
0 answers
46 views

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
  • 28.9k
5 votes
1 answer
227 views

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
2 votes
0 answers
82 views

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
  • 373
1 vote
1 answer
101 views

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
  • 28.9k
1 vote
1 answer
157 views

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
  • 28.9k
3 votes
2 answers
102 views

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
  • 938
5 votes
1 answer
282 views

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
  • 151
5 votes
2 answers
1k views

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
  • 938
7 votes
2 answers
1k views

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
  • 173
2 votes
1 answer
70 views

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
1 vote
0 answers
147 views

Interleave Bits Generically

This commonly referenced "bit twiddling" site has an interesting algorithm for interleaving the bits of two 32-bit integers. Here is my attempt at completely generalizing the algorithm using ...
Kittoes0124's user avatar
  • 1,940
6 votes
3 answers
814 views

C++ Bitwise adjacency matrix implementation

I have tried to implement a bitwise adjacency matrix to represent a graph with a fixed number of vertices. Instead of wastefully representing each connection with an integer, 64 connections are ...
Paradox's user avatar
  • 163
2 votes
1 answer
113 views

Leetcode 137: Single Number II -- python bit operations

I solved LeetCode 137 in C++. TLDR of the problem: array of numbers, nums is given; all numbers appear 3 times, except one which appear only once. Find the number ...
Mircea's user avatar
  • 322
3 votes
1 answer
80 views

Access integer field in network packet

I see three complexities in accessing (reading/writing) integer field in network packet. Handle endianness. Integer in network packet is big-endian (BE). The host may be either big-endian or little-...
Lingxi's user avatar
  • 818

15 30 50 per page
1
2 3 4 5
23