Hot answers tagged

57 votes

Floating Point XOR

x86-64 machine code, 4 bytes 0f 57 c1 c3 In assembly: xorps xmm0, xmm1 ret This is a callable function that takes two floats ...
harold's user avatar
  • 1,419
50 votes
Accepted

Cheating a multiple choice test

Jelly, 7 6 bytes _/ị“ḃ» Typing on phone. Will add description. (1,0) goes to A, ...
lirtosiast's user avatar
  • 21.4k
42 votes

Find the number of leading zeroes in a 64-bit integer

x86_64 machine language on Linux, 6 bytes 0: f3 48 0f bd c7 lzcnt %rdi,%rax 5: c3 ret Requires Haswell or K10 or ...
ceilingcat's user avatar
  • 7,485
36 votes

Xorting an array

Pyth, 40 36 31 30 bytes Ju.|G^2slHxMf>FT.:Q2Z|tSIxRJQJ Try it online: Demonstration or Test Suite Each of the big test-cases finishes in a couple of seconds. ...
Jakube's user avatar
  • 21.9k
33 votes

Golf bit weaving

Python 2.7, 44 -> 36 bytes lambda x:x/4&42|x*2&128|x*4&84|x/2&1
Arfie's user avatar
  • 1,241
29 votes

Different number, same weight

x86-64 assembly, 5 4 bytes 0: 97 xchg %eax,%edi 1: d1 c0 rol %eax 3: c3 retq A ...
Anders Kaseorg's user avatar
25 votes

Calculate the longest series of 1's in an integer's binary value

JavaScript (ES6),  33  32 bytes f=x=>x&(k=x>>1)?f(x&k):k&&1+f(k) Try it online! JavaScript (ES6),  41 40 36  34 bytes Saved 4 bytes ...
Arnauld's user avatar
  • 191k
25 votes

Find the number of leading zeroes in a 64-bit integer

Hexagony, 78 70 bytes 2"1"\.}/{}A=<\?>(<$\*}[_(A\".{}."&.'\&=/.."!=\2'%<..(@.>._.\=\{}:"<><$ Try it online! Isn't this challenge ...
DELETE_ME's user avatar
  • 17.3k
22 votes
Accepted

Calculate the longest series of 1's in an integer's binary value

Jelly, 10 8 bytes Ba\ÐƤṀċ¬ Try it online! How it works ...
Dennis's user avatar
  • 210k
21 votes

The XOROR sequence

Mathematica, 133 bytes ...
hYPotenuser's user avatar
20 votes

Compress 8 bits to 6 when certain bit patterns will never occur

Python, 60 bytes l=[n^170for n in range(256)if n&n*2<1] l.index,l.__getitem__ Try it online! l.index compresses and <...
xnor's user avatar
  • 144k
17 votes

Bitflip and negate

Python, 32 bytes lambda x:("-~"*abs(x))[x<0:]+"0" Anonymous lambda function. Given an integer x writes "-~" abs(x) times and ...
KarlKastor's user avatar
  • 2,392
16 votes

Bitflip and negate

JavaScript (ES6), 33 31 bytes f=x=>x<0?"~"+f(~x):x&&"-"+f(-x) Recursion < built-ins < loops (at least in this case). Basically unevaluates ...
ETHproductions's user avatar
16 votes

XOR of independent Bernoulli variables

Haskell, 23 bytes foldr1$ \x p->x+p-2*p*x Try it online! If you have two events with probabilities x and ...
xnor's user avatar
  • 144k
15 votes

Xorting an array

Ruby 2, 119 ->a,*o{a.each_cons(2){|x,y|x==y||o[i=(x^y).bit_length-1]==1-(o[i]=x[i])&&(return-1)};(o.map(&:to_i).reverse*'').to_i 2} Runs in 42 ...
histocrat's user avatar
  • 22.1k
15 votes

Split a byte array into a bit array

Pyth, 18 17 bytes iR2c.[t.B+C1z\0QQ Thanks to @lirtosiast for a byte! ...
Doorknob's user avatar
  • 71.4k
15 votes

Golf bit weaving

Evil, 3 characters rew Try it online! Input is in base 256, (e.g. ASCII), e.g. to enter the digit 63, enter ASCII 63 which is ?....
DJMcMayhem's user avatar
14 votes

Compute the Binary Sierpinski Triangle Sequence

05AB1E, 5 4 bytes I proudly present to you, 05AB1E. Although it is very short, it is probably very bad at long challenges. Thanks to ETHproductions for shaving off 1 byte :) ...
Adnan's user avatar
  • 44.3k
14 votes

Toggle some bits and get a square

Ruby, 74 bytes ->n{(1..n).map{|x|a=(n^x*x).to_s 2;a.size>Math.log2(n)?n:a.count(?1)}.min} Try it online! This simply generates the sequence \$\left[1^2, 2^...
Doorknob's user avatar
  • 71.4k
14 votes

Can a neural network recognize primes?

Trial division: score 59407, 6243 layers, 16478 neurons in total Given as a Python program which generates and validates the net. See the comments in trial_division...
Peter Taylor's user avatar
  • 43.1k
13 votes

Split a byte array into a bit array

Jelly, 13 bytes 1;ḅ256æ«BḊsḄṖ This takes the input as a list of integers. Try it online! How it works ...
Dennis's user avatar
  • 210k
13 votes
Accepted

Mean bits: an average challenge

Pyth, 6 bytes .Oml.B Try it online here. ...
Maltysen's user avatar
  • 25.7k
13 votes

Calculate the longest series of 1's in an integer's binary value

x86/x86-64 machine code, 14 bytes (TODO: 13 bytes with input in EAX, return value in EDX). Using @Arnauld's algorithm of x &= x>>1 and taking the highest ...
Peter Cordes's user avatar
  • 4,797
12 votes

Compute the Binary Sierpinski Triangle Sequence

Pari/GP, 27 bytes n->lift(Mod(x+1,2)^n)%(x-2) The function takes the \$n\$-th power of the polynomial \$x+1\$ in the ring \$\mathbb{F}_2[X]\$, lifts it to \$\...
alephalpha's user avatar
  • 47.5k
12 votes
Accepted

Produce an XOR table

MATL, 10 bytes 0i2$:tXgZ~ The compiler (and in particular this program) now seems to work in Octave, although it still needs some refinement. You can ...
Luis Mendo's user avatar
  • 104k
12 votes

Compute CRC32 Hash

Intel x86, 34 30 29 27 bytes Takes the address of the zero-terminated string in ESI, and returns the CRC in EBX: ...
Mark Adler's user avatar
12 votes
Accepted

"Bit-borrow" two numbers

Jelly, 11 bytes ~1¦&N$^µ</¿ Try it online! or verify all test cases. Background We can extract the last set bit of an integer n as follows. n + 1 ...
Dennis's user avatar
  • 210k
12 votes

Folding Numbers

Jelly, 9 bytes Bœs2µḢ^UȦ Try it online! or verify all test cases. How it works ...
Dennis's user avatar
  • 210k
12 votes

Alternating bit smearing

Python 3, 20 bytes lambda n:(n&-n)//3+n Try it online! Explanation Take 192 as an example. Its binary form is ...
Leaky Nun's user avatar
  • 49.7k
12 votes

Find the number of leading zeroes in a 64-bit integer

Python, 31 bytes lambda n:67-len(bin(-n))&~n>>64 Try it online! The expresson is the bitwise & of two parts: <...
xnor's user avatar
  • 144k

Only top scored, non community-wiki answers of a minimum length are eligible