Questions tagged [bitwise]
For challenges involving bitwise commands or manipulation of numbers at the bit level
79 questions
11
votes
7
answers
739
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 ...
8
votes
7
answers
950
views
Conversion between CESU-8 and UTF-8 (for supplementary characters)
The Compatibility Encoding Scheme for UTF-16: 8-Bit, also known as CESU-8, is a Unicode encoding that is not part of the Unicode standard, but mentioned in a Unicode Technical Report as a ...
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 ...
5
votes
9
answers
362
views
Reorder a string of length \$2^n\$ by permuting the \$n\$ binary digits of every index
Given a binary string \$s\$ of length \$2^n\$ and a permutation \$\sigma\$ of \$\{1,\dots,n\}\$, generate the binary string \$u\$ of length \$2^n\$ which is a reordering of \$s\$ such that \$u[i^\...
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 ...
18
votes
12
answers
2k
views
Is it a valid ARM immediate value?
Exposition
In this challenge, I am talking about ARM assembly language. ARM is a 32-bit RISC processor; I'll use instruction set up to architecture v6.
To load a constant ("immediate") value ...
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 ...
2
votes
0
answers
272
views
making a binary string palindrome using xor operations [closed]
Problem
You are given a binary string A of length N.
You can perform the following type of operation on the string A:
Choose two different indices \$i\$ and \$j\$ (\$1 \le i\$, \$j \le N\$)
Change \$...
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 ...
2
votes
3
answers
346
views
Shift distance of number [closed]
Given two non-zero 16-bit integers a and b, decide the smallest number of shift operations needed to turn ...
9
votes
3
answers
540
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 ...
9
votes
2
answers
692
views
Inverting string-based binary number in one line in Python
I want to read two strings on separate lines, each string the same length and containing only 0's and 1's, and determine if the first is the one's complement of the second. How succinctly can this be ...
4
votes
19
answers
714
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. ...
0
votes
4
answers
158
views
Calculate the truncated log2 of some unsigned integer [duplicate]
Definition
Given some number, x calculate the smallest number i such that 2i≥x. This is not a duplicate of this question. It is slightly different in that an input of 16 should yield an output of 4 ...
6
votes
3
answers
462
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 ...