# Search Results

Results tagged with Search options answers only user 17602
20 results

For challenges involving doing something on the bit level.

Batch, 92 bytes @set m=%1 @set f=@for %%i in (%*)do @ %f%set/a"m=m+(m-=%%i)*(m>>31) %f%cmd/cset/a!(m-%%i) Takes arguments as command-line parameters in reverse order. Works by arithmetically calcul …
JavaScript (ES6), 32 bytes (n,m=32)=>(--m&&f(n,m)*2)|n>>m&1 Wrote this while trying to solve Bit-Reversal Permutations - it didn't help there, but it works fine here!
answered Jun 20 '16 by Neil
JavaScript (ES6), 120 bytes f=(a,n,b=0,t=0,r=[])=>b<n?a.length?f(a.slice(1),n,b+8,t*256+a,r):b?[...r,t<<n-b]:r:f(a,n,b-=n,t&(1<<b)-1,[...r,t>>b]) Recursive bit twiddling on integer arrays. Ungol …
answered Mar 22 '16 by Neil
vi, 27 bytes 8I0<ESC>$7hc0lxp<ESC>l"qd0xp3@q03@q Where <ESC> represents the Escape character. I/O is in binary, output is padded. 24 bytes in vim: 8I0<ESC>$7hd0xpqqlxpq2@q03@q
answered Jun 30 '16 by Neil
JavaScript (ES6), 180 bytes f=(s,t=(s+\0\0\0\0).replace(/[^]/g,(c,i)=>(c.charCodeAt()+256*!!i).toString(2).slice(!!i)))=>t?f(s,t.replace(/.(.{32})/,(_,m)=>(('0b'+m^79764919)>>>0).toString(2))): …
answered May 1 '16 by Neil
Charcoal, 25 bytes ⭆θ◧⍘℅ι²¦⁷←Ｗⅈ←Ｉ﹪⍘ＫＤ²←01 ²1 Try it online! Link is to verbose version of code. Explanation: ⭆θ◧⍘℅ι²¦⁷← Convert all the characters to binary and pad them to a length of 7 and the …
Charcoal, 11 bytes Ｉ↨﹪θ¹²⁸¦¹²⁸ Try it online! Link is to verbose version of code. Takes input as an array. Explanation: θ Input array ﹪ ¹²⁸ Elementwise modulo 128 ↨ ¹²⁸ Conver …
ES6, 84 bytes a=>(i=e=0,a.reduce((x,y)=>(z=1<<31-Math.clz32(x^y),x>y?i|=z:y>x?e|=z:z,y)),i&e?-1:i) Edit: By the time it took me to write the answer the algorithm had already been independently post …
answered Dec 31 '15 by Neil
JavaScript (ES6), 34 33 bytes f=n=>n?f(n&1?~n:n/2)+'<~'[n&1]:'' <input type=number oninput=o.textContent=f(this.value)><pre id=o> Works for any 32-bit integer.
answered May 6 '17 by Neil
ES6, 130 bytes (n,m)=>{for(a={},s=0,i=x=y=1;i<<1;i+=i,z=y,y=x,x+=z)s+=((n&i)+(m&i))/i*(a[i]=x);for(r=0;i;i>>>=1)s>=a[i]?(s-=a[i],r|=i):0;return r} I originally tried to compute the sum in-place (ef …
answered Jan 31 '16 by Neil
JavaScript (ES6), 84 72 bytes (s,p)=>(t=p>'e',[...s].map(c=>t^=c.charCodeAt()),t^=t/16,t^=t/4,t^t/2)&1 Bit twiddling turned out to be shorter than converting to base 2 and counting 1s.
answered Apr 25 '16 by Neil
Charcoal, 31 bytes ＮθＩ⌊ＥΦＥθ↨×ιι²⁼ＬιＬ↨θ²ΣＥ↨θ²¬⁼λ§ιμ Try it online! Link is to verbose version of code. Explanation: Ｎθ Input N θ N Ｅ …
answered Aug 8 '18 by Neil
JavaScript (ES6), 30 bytes f=n=>n*4&84|n*2&128|n/2&1|n/4&42
answered Jun 29 '16 by Neil
JavaScript (ES6), 31 bytes (n,m)=>n^m&(n^(n*=257)>>1^n>>7)
answered Nov 5 '16 by Neil
JavaScript (ES6), 33 bytes f=(n,m)=>n<m?f(n|n+1,m&m-1):[n,m] Simple port of the answers by @miles.
answered Jun 17 '16 by Neil

15 30 50 per page