Created
January 15, 2016 13:28
-
-
Save shkesar/d2bdfee61fc3171d1171 to your computer and use it in GitHub Desktop.
Number to Array of Bits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def toBitSet(n: Int, size: Int): Array[Int] = { | |
var (a, idx) = (n, 0) | |
val bits = new Array[Int](14) | |
while (a > 0) { | |
if (a % 2 != 0) bits(idx) += 1 | |
else bits(idx) += 0 | |
a = a >> 1 | |
idx += 1 | |
} | |
bits | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment