Skip to content

Instantly share code, notes, and snippets.

@shkesar
Created January 15, 2016 13:28
Show Gist options
  • Save shkesar/d2bdfee61fc3171d1171 to your computer and use it in GitHub Desktop.
Save shkesar/d2bdfee61fc3171d1171 to your computer and use it in GitHub Desktop.
Number to Array of Bits
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