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

Break an integer into even- and odd-indexed bits

$
0
0

Objective

Given an integer \$n\$ interpreted as two's complement binary, output two integers, namely the integer consisting of \$n\$'s bits at places of \$2^0, 2^2, 2^4, \cdots\$, and the integer consisting of \$n\$'s bits at places of \$2^1, 2^3, 2^5, \cdots\$.

Note that the input may be negative. Since \$n\$ is interpreted as two's complement binary, nonnegative integers start with infinitely many zeros, and negative integers start with infinitely many ones. As a consequence, nonnegative inputs split into nonnegative outputs, and negative inputs split into negative outputs.

Examples

Here, the integers are represented as decimal.

Input, Output even, Output odd0, 0, 01, 1, 02, 0, 13, 1, 14, 2, 05, 3, 06, 2, 17, 3, 18, 0, 29, 1, 210, 0, 311, 1, 312, 2, 213, 3, 214, 2, 315, 3, 3-1, -1, -1-2, -2, -1-3, -1, -2-4, -2, -2

I/O format

Flexible; default I/O policies apply.


Viewing all articles
Browse latest Browse all 15

Trending Articles



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