Quantcast
Channel: Break an integer into even- and odd-indexed bits - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 15

Answer by ovs for Break an integer into even- and odd-indexed bits

$
0
0

K (ngn/k), 22 bytes

Returns odd output before even output.

2/64 2#,/|@\^:\(64#2)\

Try it online!

(64#2)\ Get an array of all bits of the integer.
,/|@\^:\ Magic incantation to repeat the leading bit 65 times. Works something like: make all bits zero, index into the array of bits, prepend that result to the bits.
64 2# Reshape the length 128 array into a matrix with two columns.
2/ Convert both columns from base 2.


Viewing all articles
Browse latest Browse all 15

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>