75
votes
The first n numbers without consecutive equal binary digits
Python 2, 36 bytes
lambda n:[2**i*2/3for i in range(n)]
Try it online! Explanation: The binary representation of \$\frac{2}3\$ is ...
63
votes
Accepted
Binary to decimal converter
Jelly, 5 bytes
DḤ+¥/
Try it online!
Explanation
The cast
D is a monad (single argument function): digits, turning ...
61
votes
How on earth did llhuii output the Evil Numbers in 42 bytes of Python?
This isn't the same solution as llhuii's, but it's also 42 bytes long.
n=0;exec'print n;n^=(n^n+2)%3/2;n+=2;'*400
Try it online!
Thanks to @JonathanFrech, we're ...
55
votes
Fizz Buzz to Text
C, 59 bytes
i;f(char*s){while(*s&3?*s&9||(i+=i+*s%5):putchar(i),*s++);}
Magic numbers, magic numbers everywhere!
(Also, C shorter than Python, JS, PHP, ...
45
votes
How on earth did llhuii output the Evil Numbers in 42 bytes of Python?
Getting 39 bytes
This is an explanation of how I got a 39-byte solution, which Dennis and JonathanFrech found separately as well. Or, rather, it explains how one could arrive at the answer in ...
42
votes
i love yOu i lOve you i love yOu!
Jelly, 41 40 35 33 bytes
Thanks to @Dennis for making the end ṖṖCG! (complement C = 1-x in ...
42
votes
Where's the 0xBEEF?
vim, 126 80 77 76
/\v1011\_.{9}(1110\_.{9}){2}1111<cr>:exe'norm Go'.join(getpos('.'))<cr>xxdawhPXXd{
Expects input in the form
...
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 ...
42
votes
Accepted
38
votes
Output numbers up to 2^n-1, "sorted"
Python, 53 bytes
f=lambda n,i=1:n*[f]and[i]+f(n-1,2*i)+i%2*f(n-1,i-~i)
Try it online!
The recursive function generates the sorted list as a pre-order walk down ...
35
votes
31
votes
Bit run rundown
Python 2, 46 45 bytes
f=lambda n,k=1:`k`in bin(n^n/2)and-~f(n,k*10)
Try it online!
How it works
By XORing n and n/2 (dividing by 2 essentially chops off the ...
31
votes
Is the number binary-heavy?
x86 Machine Code, 15 14 bytes
F3 0F B8 C1 0F BD D1 03 C0 42 2B D0 D6 C3
This is a function using Microsoft's __fastcall calling convention (first and only ...
30
votes
Accepted
Where's the 0xBEEF?
Jelly, 20 17 16 bytes
ṡ€4ḄZw€“¿ÇÇБĖUṀ
Input is in form of a Boolean matrix, output is the 1-based index pair (Y, X).
Try it online! or verify all test cases.
...
30
votes
Accepted
29
votes
28
votes
In how many bits do I fit
x86 Assembly, 4 bytes
Assuming Constant in EBX:
bsr eax,ebx
inc eax
EAX contains the number of bits necessary for Constant.
...
26
votes
Only Even Bytes
GS2, 4 bytes
dΦ("
Try it online!
Hexdump
0000000: 64 e8 28 22 d.("
How it works
...
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 ...
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 ...
24
votes
Is it a Cyclops number? "Nobody" knows!
Python 2, 30 bytes
lambda n:(2*n^2*n+3)**2==8*n+9
Try it online!
Note that 2*n^2*n+3 is the bitwise xor of ...
23
votes
Numbers with multiple runs of ones
Python, 48
lambda n:[i for i in range(2**n)if'01'in bin(i)]
I had been vastly overthinking this. We just need to check if the binary expansion contains ...
23
votes
JFor? More like XNor
Python, 34 bytes
lambda a,b:bin(a&b).count('01')==1
Try it online!
Although this doesn't use xor, I'm xnor.
22
votes
Accepted
16-bit binary grid
J, 26 bytes
(' ';' # '){~4 4$_16{.#:
An anonymous verb. Thankfully, J is very good at drawing boxes. Let's try it out:
...
22
votes
22
votes
Where's the 0xBEEF?
JavaScript (ES6), 63 60 56 bytes
s=>[(i=s.search(/1011.{9}(1110.{9}){2}1111/))%13,i/13|0]
Takes input as a 155-character space-delimited string of 12 12-digit ...
22
votes
Complex Binary Numbers
MATL, 7 bytes
BJ*Y'^s
Try it online!
How it works
Consider input 4538 for example.
...
22
votes
Binary to decimal converter
Python 2, 49 37 31 30 Bytes
Now this will take a binary number in a decimal representation, since Python can handle arbitrarily large integers.
...
22
votes
A bit, a nibble or byte?
Python, 39 bytes
f=lambda n:4**(n>1)*(n<16)or 2*f(n**.5)
Counts how many times one must take the square root for n to ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
binary × 232code-golf × 215
number × 41
sequence × 41
base-conversion × 30
math × 23
string × 22
integer × 19
decision-problem × 14
bitwise × 14
arithmetic × 9
number-theory × 8
encoding × 8
ascii-art × 7
fastest-code × 7
combinatorics × 6
primes × 6
restricted-source × 5
coding-theory × 5
code-challenge × 4
tips × 4
subsequence × 4
palindrome × 4
conversion × 4
binary-matrix × 4