Bitmap { static int[] getBits(final int bitmap) { int[] bits = new int[10]; int value = bitmap; int bit = 0; int pos = 0; while (value > 0) { if ((value & 1) != 0) { if (bits.length == pos) { final int[] tmp = new int[pos * 2]; System.arraycopy(bits, 0, tmp, 0, pos); bits = tmp; } bits[pos] = bit; pos++; } value = value >> 1; bit++; } final int[] trimmed = new int[pos]; System.arraycopy(bits, 0, trimmed, 0, pos); return trimmed; }    }
@Test void testBitmap() { final int input = 0x1001; dumpBits(input); assertThat(Bitmap.getBits(input)) .containsExactly(0,12); }
@Test void testBitmap2() { final int input = 0x66; dumpBits(input); assertThat(Bitmap.getBits(input)) .containsExactly(1, 2, 5, 6); }
@Test void testBitmap3() { final int input = 0x0; dumpBits(input); assertThat(Bitmap.getBits(input)) .isEmpty(); }
@Test void testBitmap4() { final int input = 0xF; dumpBits(input); assertThat(Bitmap.getBits(input)) .containsExactly(0, 1, 2, 3); }