Skip to main content
Share Your Experience: Take the 2024 Developer Survey
6 votes

Construct a uInt from an array of bits

APL (dzaima/APL), 1 byte Try it online! Fun fact: This exact functionality was available in APL's precursor already in 1962.
Adám's user avatar
  • 30.3k
5 votes

Construct a uInt from an array of bits

APL+WIN, 17 12, 9, 3 bytes -5 bytes thanks to Adám. Prompts for input as either boolean or 'true' 'false' as per original question. 2⊥(↑¨⎕)∊'t'1 Try it online! ...
Graham's user avatar
  • 6,226
5 votes

Construct a uInt from an array of bits

JavaScript (ES6), 18 bytes Expects an array of binary digits. a=>'0b'+a.join``-0 Try it online! JavaScript (ES6), 26 bytes Expects an array of either binary ...
Arnauld's user avatar
  • 193k
4 votes

Construct a uInt from an array of bits

C (gcc), 38 bytes -6 bytes thanks to @AZTECCO f(a,n)int*a;{n=n--?f(a+1,n)|*a<<n:*a;} Try it online! A port from this answer. I tried to use ...
badatgolf's user avatar
  • 1,327
4 votes

Construct a uInt from an array of bits

Python 3, 29 bytes lambda a:int('%d'*len(a)%a,2) Try it online! Python 3, 33 bytes f=lambda a:a>[]and a.pop()+2*f(a) Try ...
Jitse's user avatar
  • 7,186
3 votes

Construct a uInt from an array of bits

Charcoal, 4 bytes I⍘S² Try it online! Link is to verbose version of code. Takes input as a string of 0s and ...
Neil's user avatar
  • 171k
3 votes

Hoop, Hoop, Hoop, Hoop, Eye-Eye-Eye-Eye

JavaScript (Node.js), 41 bytes f=x=>x?(f(--x/10|0)+(e^=1)<<1+x%10)-e:e=0 Try it online!
l4m2's user avatar
  • 24.4k
3 votes

Hoop, Hoop, Hoop, Hoop, Eye-Eye-Eye-Eye

Charcoal, 31 bytes NθWθ«⊞υ∨﹪θχχ≔÷⊖θχθ»I⍘⭆⮌υק10κι² Try it online! Link is to verbose version of code. Explanation: ...
Neil's user avatar
  • 171k
2 votes

Construct a uInt from an array of bits

PARI/GP, 15 bytes a->Pol(a)%(x-2) Attempt This Online! Converts the input list to a polynomial, and then evaluates it at x=2....
alephalpha's user avatar
  • 48.2k
2 votes

Construct a uInt from an array of bits

Dart, 78 bytes int f(var l){int x=0;for(var i=0;i<l.length;i++)x+=(x+l[i]).toInt();return x;} Needs a list of 0s and 1s to work.
Redz's user avatar
  • 121
2 votes

Construct a uInt from an array of bits

TI-BASIC, 30 28 bytes Removed 2 bytes thanks to MarcMush Input L₁ dim(L₁ Σ(2^(Ans-I)L₁(I),I,1,Ans Takes an array of bits as input, and outputs the converted ...
Sylvester is on codidact.com's user avatar
1 vote

Hoop, Hoop, Hoop, Hoop, Eye-Eye-Eye-Eye

05AB1E, 21 18 bytes [D_#<T‰`ˆ}TÞ¯R>×JC Port of @Neil's Charcoal answer, so make sure to upvote that answer as well! -3 bytes thanks to @Neil For a language ...
Kevin Cruijssen's user avatar
1 vote

Hoop, Hoop, Hoop, Hoop, Eye-Eye-Eye-Eye

Jelly, 7 bytes ḃ⁵Jx$ḂḄ A monadic Link that accepts a non-negative integer and yields a non-negative integer. Try it online! Or see the test-suite. How? ...
Jonathan Allan's user avatar
1 vote

Construct a uInt from an array of bits

MATLAB, 25 bytes Built-in function bin2dec() takes character arrays, so we need to convert from a logical array. For golfing, we save a handle to an anonymous function. ...
rst's user avatar
  • 41
1 vote

Construct a uInt from an array of bits

Uiua Without using a builtin (10 bytes): /+×ⁿ:2⇡⧻.⇌ With builtins (3 bytes): °⋯⇌ Try it online!
Small-Jaguar's user avatar
1 vote

Construct a uInt from an array of bits

MathGolf, 2 bytes Try it online. Could have been 1 byte if we'd be allowed to input as a string instead of bit-array: å Try ...
Kevin Cruijssen's user avatar
1 vote

Construct a uInt from an array of bits

C++ (gcc), 85 81 80 74 72 bytes (-4 because of badatgolf) (-1) (-6 due to yksisarvinen) (-2 because of badatgolf again) I'm certain there are ways to optimize this, but I'm pretty proud of it. It ...
Someone's user avatar
  • 325
1 vote

Construct a uInt from an array of bits

Python 2, (17?) 25 bytes lambda b:int(`b`[1::3],2) An unnamed function that accepts a non-empty list of integers from \$(0,1)\$ and returns an integer. Try it ...
Jonathan Allan's user avatar
1 vote

Construct a uInt from an array of bits

Google Sheets, 20 bytes =bin2dec(join(,A:A)) Put the array of bits in column A1:A as zeros and ones, and the formula in cell <...
doubleunary's user avatar
  • 1,688
1 vote

Construct a uInt from an array of bits

Ruby, 18 bytes ->b{(b*"").to_i 2} Try it online!
AZTECCO's user avatar
  • 10.8k
1 vote

Borders of a Rectangular Matrix

Pip -xp, 11 bytes L4PDQ R:Z:a Outputs (up to) four lists: down the left border, then right-to-left along the top border, then ...
DLosc's user avatar
  • 39.5k
1 vote

Half, Half Half, and, Half

Uiua 0.11.0, 11 bytes Accepts N, returns the numerator of the Nth term first, then the denominator. ⟜◿⍜ₙ⌊2.+1×2 Try it out! Not only does it work on scalars, it ...
RomanPro100's user avatar

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