New answers tagged binary
0
votes
Binary to decimal converter
Desmos, 51 bytes
f(n)=∑_{i=0}^{log(n+0^n)}2^imod(floor(n/10^i),10)
Try It On Desmos!
Try It On Desmos! - Prettified
Without the ban on binary list input, this ...
- 11.3k
3
votes
2
votes
4
votes
How many xor'ed waves?
05AB1E, 37 30 bytes
āεÅ1D_«Iû∍ŒIgù}€`æé.ΔIš.«^O_}g
Input as a list.
Brute-force, and extremely slow (times out for test cases of length \$n>4\$).
Try it online ...
- 116k
7
votes
6
votes
How many xor'ed waves?
Charcoal, 40 37 bytes
⊞υSWΣ⌊υ«≔ΣEυΣEκE⊗⊕ν⭆κ﹪⁺Iρ÷⁻ςξ⊕ν²υ→»Iⅈ
Attempt This Online! Link is to verbose version of code. Explanation:
...
- 156k
7
votes
How many xor'ed waves?
Pyth, 41 39 bytes
K]QWshK=hZ=KSmxMCd*Ksm.:*lQS*hdU2lQlQ;Z
Try it online!
Explanation
...
- 2,107
2
votes
Advanced Binary Number System
Pyt, 6 bytes
Đɓř2Ĩɔ
Try it online!
Port of caird coinheringaahing's Jelly answer
...
- 1,317
0
votes
Is the number binary-heavy?
Go, 101 bytes
import(."strconv";."strings")
func f(n int64)bool{x:=FormatInt(n,2)
return Count(x,"1")>Count(x,"0")}
...
- 9,406
0
votes
Is the number binary-heavy?
Turing Machine Code, 332 bytes
Terminates in state halt for truthy, or halt-r for falsey.
...
- 11.8k
1
vote
Is the number binary-heavy?
JavaScript (Node.js), 47 bytes
Different approach but can't beat the best JS answers.
l=>[...l.toString(2)].map(e=>a+=e*2-1,a=0)&&a>0
Try it ...
- 581
0
votes
Is the number binary-heavy?
Thunno, \$8\log_{256}(96)\approx\$ 6.58 bytes
bD1cs0c>
Attempt This Online!
Explanation
...
- 9,406
0
votes
2
votes
1
vote
Number to Binary
Raku, 8 bytes
.base(2)
Try it online!
The above version operates on the current topic, as seen in the demo code. To make it a function accepting an argument, just ...
- 905
3
votes
1
vote
Bubbler numbers
Vyxal, 11 bytes
bṅÞS'3/≈;h≈
Try it Online! or get all the Bubbler numbers up to a given number.
Port of Kevin Cruijssen's 05AB1E answer. Outputs \$0\$ for truthy ...
- 9,406
0
votes
Bubbler numbers
PowerShell Core, 74 bytes
($s=[Convert]::ToString("$args",2))-notmatch'(.)\1\1'*($s-match'(.+)\1\1')
Try it online!
- 2,308
8
votes
Number to Binary
Piet + ascii-piet, 29 bytes (6×9=54 codels)
tkvuumf_iliqqdltT QqKln?_sf ?
Try Piet online!
B2C2 is I (no-op). The printing ...
- 70k
1
vote
Largest Binary Area
Python 3.8, 85 bytes
lambda n:max((j:=2**len(bin(n))>>3)-1,sum(bin(i*2)[2:].find('0')for i in range(j,n)))
An anonymous function that accepts a positive ...
- 97.9k
0
votes
Number to Binary
J 2 bytes
#:
Some test cases:
#:12345
1 1 0 0 0 0 0 0 1 1 1 0 0 1
#:33
1 0 0 0 0 1
1
vote
Number to Binary
Knight (v2), 29 bytes
;=a@;=n*2P;W=n/n 2=a+,%n 2aOa
Try it online!
Zero outputs nothing, which is allowed in the rules.
- 11.3k
2
votes
Largest Binary Area
Jelly, 12 11 bytes
B«\)LÐṀFS)Ṁ
A monadic Link that accepts \$n\$ and yields the largest binary area when arranging the numbers \$1\$ to \$n\$ inclusive.
Try it ...
- 97.9k
2
votes
Largest Binary Area
Charcoal, 28 bytes
FN«≔⁺∧&ι⊕ιθL§⪪⍘⊕ι²0⁰θ⊞υθ⟦I⌈υ
Try it online! Link is to verbose version of code. Outputs the first n terms. ...
- 156k
2
votes
2
votes
Largest Binary Area
Python, 95 93 92 88 bytes
m=n=0
while g:=lambda k:k and(k&k+1<1)+g(k>>1):print(m:=max(m,s:=n&(n:=n+1)<1or g(n)+s))
Attempt This Online!
Outputs ...
- 9,406
9
votes
Largest Binary Area
JavaScript (V8), 67 bytes
Prints the sequence infinitely.
for(m=n=0;g=k=>k?!(k&k+1)+g(k>>1):s;print(m=m>s?m:s))s=n&++n?g(n):1
Try it online!
...
- 179k
7
votes
Largest Binary Area
MATL, 14 13 bytes
1 byte saved thanks to @Suever
:B4&1ZIXz5#XM
Inputs n and outputs the ...
- 102k
0
votes
Number to Binary
Simply, 17 bytes
The code simply creates an anonymous arrow function that calls the &tb function, and returns the result.
...
- 7,825
1
vote
Number to Binary
CJam, 2 bytes
Yb
Try it online!
Link includes test cases
Explanation
b # Convert to base
Y # builtin *2*
For fun, here's one ...
- 767
2
votes
Number to Binary
R, 9 bytes
intToBits
Attempt This Online!
Outputs as little-endian with trailing zeros.
R, 18 bytes
\(n)n%/%2^(n:0)%%2
...
- 13.8k
1
vote
Number to Binary
Jelly, 1 byte
B
Try it online!
Lmao my first answer in Jelly. Just a builtin.
- 11.3k
2
votes
Number to Binary
Alice, 25 bytes
/O \v$.:2[!<
@Mq/>.2%'0+^
Try it online!
This explanation below are still valid, I just reorganised the flow to save two bytes
...
- 2,308
1
vote
Number to Binary
SNOBOL4 (CSNOBOL4), 70 bytes
I =INPUT
N O =REMDR(I,2) O GT(I) :F(O)
I =I / 2 :(N)
O OUTPUT =O
END
Try it online!
- 27.3k
0
votes
Convert a decimal integer to binary only using arithmetic operators
Pascal, 160 B
This is a complete program according to ISO standard 7185 “Standard Pascal” using your standard Horner scheme recursively.
...
- 453
3
votes
Number to Binary
Haskell, 62 bytes
import Data.Sequence
d 0=Nothing
d n=Just$divMod n 2
unfoldl d
Attempt This Online!
A different approach than Aiden Chow's answer; this one uses ...
- 36.2k
6
votes
Number to Binary
Quipu, 78 bytes
2&1@0&2&0&3&
//**[][][][]
1&2&2&++1&/\
>>>>%% --
\/1&1& 0&
[] >>
**
...
- 36.2k
1
vote
0
votes
2
votes
Number to Binary
PHP, 6 bytes
decbin
Try it online!
No PHP answer yet? Surprisingly competitive this time!!!
- 2,727
6
votes
Number to Binary
Haskell, 31 bytes
f 0=0
f n=n`mod`2+10*f(n`div`2)
Try it online!
I'm unsure why f$n`div`2 doesn't work as opposed to ...
- 11.3k
1
vote
Number to Binary
APL(Dyalog Extended), 9 1 byte SBCS
⊤
Try it on APLgolf!
Literally a builtin... What more can I say?
- 11.3k
1
vote
5
votes
Number to Binary
Prolog (SWI), 26 bytes
:-read(X),format("~2r",X).
Try it online!
With builtin.
Prolog (SWI), 42 36 35 bytes
-6 bytes thanks to @Steffan
-1 byte thanks to ...
- 11.3k
5
votes
Number to Binary
Befunge-93 (PyFunge), 28 bytes
2&v
2/>:0`!#^_:2%\
._@#-2:<
Try it online!
Explanation:
2&v and ...
- 111
10
votes
Number to Binary
Piet + ascii-piet, 50 44 42 bytes (2×25=50 2×22=44 2×21=42 codels)
tabru?qd?t?itknmdjem_ a?liqdltailckt?iq ?
Try Piet online!
Pointer Path
- 11.3k
2
votes
Number to Binary
JavaScript (Node.js), 22 bytes
f=n=>n?f(n/2|0)+n%2:""
Try it online!
Not quite as short as the builtin but wanted to get a short solution doing it ...
- 1,597
3
votes
Number to Binary
Desmos, 50 bytes
f(n)=mod(floor(n/2^{[floor(log_2(n+0^n))...0]}),2)
Try It On Desmos!
Try It On Desmos! - Prettified
- 11.3k
3
votes
Number to Binary
Scratch, 70 68 bytes
Puts a list of binary digits onto the a global variable, which is automatically displayed when the program finishes execution.
Saved 2 bytes by ...
- 1,597
3
votes
Number to Binary
J, 2 bytes
#:
Attempt This Online!
#: returns the binary expansion of a given number y as a boolean list.
- 1,110
Top 50 recent answers are included
Related Tags
binary × 224code-golf × 209
number × 39
sequence × 39
base-conversion × 29
math × 22
string × 21
integer × 18
decision-problem × 14
bitwise × 13
arithmetic × 9
number-theory × 8
encoding × 8
ascii-art × 7
combinatorics × 6
primes × 6
fastest-code × 6
restricted-source × 5
subsequence × 4
conversion × 4
binary-matrix × 4
coding-theory × 4
code-challenge × 3
kolmogorov-complexity × 3
tips × 3