Questions tagged [bitwise]
For challenges involving bitwise commands or manipulation of numbers at the bit level
79 questions
11
votes
7
answers
737
views
On the Subject of Switches
This challenge is from a video game, Keep Talking And Nobody Explodes.
A yes or no choice isn’t too bad. Unfortunately you have to make five of them and any of them could be your last. — from the ...
13
votes
17
answers
2k
views
Find the Smallest Data Type for a Number
Recently I had to implement this problem in c#, and thought it would make for a good code golf.
Your goal is to output the smallest unsigned data-type a 64 bit unsigned number can fit into.
Input: An ...
22
votes
2
answers
2k
views
Fast leap year check
The task is to find parameters that make a fast leap year check correct for the widest range of years.
We assume the Proleptic Gregorian calendar, which extends the Gregorian calendar backward from ...
17
votes
18
answers
2k
views
XOR of independent Bernoulli variables
In probability theory, a Bernoulli variable is a random variable which has a single parameter \$p\$, and is equal to 1 with probability \$p\$, and 0 with probability \$1-p\$.
In this challenge, there ...
15
votes
3
answers
621
views
Count the number of disjoint 11 blocks
The task is to count the number of disjoint 11 blocks in a 64-bit word, using the minimum number of straight-line instructions. That is, how many nonoverlapping ...
9
votes
3
answers
537
views
Smallest and largest 100-bit square with maximum Hamming weight
Introduction
In the binary representation of a \$k-\$bit \$(k>1)\$ square number \$n^2, \$ not all bits can be \$1\$. The maximum number of \$1\$-bits (Hamming weight, \$B\$ for short) is given in ...
4
votes
19
answers
713
views
Double bit rotation to the right [closed]
Given a positive integer as input, output that integer, but with its bits rotated two times to the right. Also, think of the number as a donut of bits, eg. ...
6
votes
3
answers
460
views
Dr. Lamport's Unfinished Business
Introduction
Dr. Leslie Lamport, of the eponymous Lamport one-time signature scheme, is getting rather old. But he can't die until his most famous algorithm gets all the kinks ironed out!
In ...
18
votes
9
answers
1k
views
The Koszul Sign Rule
A Bit of Background
The exterior algebra is a central object in topology and physics (for the physics concept cf. fermion). The basic rule dictating the behavior of the exterior algebra is that \$yx =...
16
votes
23
answers
2k
views
Summing a sub-square of a quarter of an infinite chessboard
Description of the problem
Imagine a quarter of an infinite chessboard, as in a square grid, extending up and right, so that you can see the lower left corner. Place a 0 in there. Now for every other ...
29
votes
12
answers
4k
views
Compress 8 bits to 6 when certain bit patterns will never occur
Consider an eight bit number in which an even position (second, fourth, etc) bit will never be 1 if one of its neighbors is 0 (considering MSB and LSB as neighbors). There are fewer than 64 such ...
-2
votes
2
answers
325
views
Mirror, Mirror, on the wall. Who's the fairest of them all?
Well, you know it's Snow White, and the evil Queen is at it again. Will Snow White be saved? Will she fall asleep once again? Will the Prince find her?
Challenge:
Given an arbitrary number (>= 2) ...
19
votes
22
answers
6k
views
Decode a variable-length quantity
A variable-length quantity (also referred to as VLQ or uintvar) is a way to encode up to a 28 bit integer value using only as many bytes as necessary. This was used ...
19
votes
22
answers
4k
views
I'm in your subnets, golfing your code
Challenge
Given an IPv4 address in dotted-quad notation, and an IPv4 subnet in CIDR notation, determine if the ...
10
votes
21
answers
2k
views
Compare four integers, return word based on maximum
This function should take four integer inputs (a,b,c,d) ...
19
votes
32
answers
9k
views
Find the number of leading zeroes in a 64-bit integer
Problem:
Find the number of leading zeroes in a 64-bit signed integer
Rules:
The input cannot be treated as string; it can be anything where math and bitwise operations drive the algorithm
The ...
20
votes
22
answers
4k
views
Double, XOR and do it again
We define the function g as g(n) = n XOR (n * 2) for any integer n > 0.
Given x > 0, find the smallest integer y > 0 such that gk(y) = x for some k > 0.
Example
...
17
votes
17
answers
4k
views
XOR sort an array
Given a key, and an array of strings, shuffle the array so that it is sorted when each element is XOR'd with the key.
XOR'ing two strings
To XOR a string by a key, XOR each of the character values ...
23
votes
2
answers
1k
views
Bitwise XOR of rational numbers
Introduction
Every rational number between 0 and 1 can be represented as an eventually periodic sequence of bits.
For example, the binary representation of 11/40 is
...
4
votes
1
answer
308
views
Find the Closest Double Palindrome
Given a double-precision float, find the closest double-precision float whose binary representation is a palindrome.
Input
A floating point number x. You may use ...
10
votes
32
answers
2k
views
Do two numbers contain unique powers of 2
Break two numbers up into their powers of 2, if they share any, return a falsey value. Otherwise, return a truthy value.
If one input is 0, the answer will always ...
18
votes
9
answers
726
views
Make Wise Numbers
Wise is a simple bitwise language I designed a while back. It is based around Python's bitwise operations. It has several operations most of these are the same or very similar to the equivalent ...
17
votes
5
answers
2k
views
Binary Convolution
A binary convolution is described by a number M, and is applied to a number N. For each bit in the binary representation of <...
38
votes
27
answers
3k
views
Folding Numbers
Given a number determine if it is a folding number.
A folding number is a number such that if you take it binary representation and "fold" it in half, That is take the result of XNOR ...
14
votes
22
answers
3k
views
Golf bit weaving
Note: the first half of this challenge comes from Martin Ender's previous challenge, Visualize Bit Weaving.
The esoteric programming language evil has an interesting operation on byte values which it ...