Here you can find the source of bitFieldToIndexArray(long bitfield)
public static short[] bitFieldToIndexArray(long bitfield)
//package com.java2s; /****************************************************************************** * Copyright (c) 2004-2008 Whirlwind Match Limited. All rights reserved. * * This is open source software; you can use, redistribute and/or modify * it under the terms of the Open Software Licence v 3.0 as published by the * Open Source Initiative./*w w w . j a va 2s . c o m*/ * * You should have received a copy of the Open Software Licence along with this * application. if not, contact the Open Source Initiative (www.opensource.org) *****************************************************************************/ public class Main { /** * Get the indexes of the values */ public static short[] bitFieldToIndexArray(long bitfield) { int entries = countBitsSet(bitfield); short[] vals = new short[entries]; int currEntry = 0; for (short i = 0; i < Long.SIZE; i++) { if ((bitfield & 0x01) != 0) { vals[currEntry++] = i; } bitfield >>>= 1; } return vals; } /** * Get the indexes of the values */ public static short[] bitFieldToIndexArray(int bitfield) { int entries = countBitsSet(bitfield); short[] vals = new short[entries]; int currEntry = 0; for (short i = 0; i < Long.SIZE; i++) { if ((bitfield & 0x01) != 0) { vals[currEntry++] = i; } bitfield >>>= 1; } return vals; } public static int countBitsSet(int bitfield) { int count = 0; for (short i = 0; i < Integer.SIZE; i++) { if ((bitfield & 0x01) != 0) { count++; } bitfield >>>= 1; } return count; } public static int countBitsSet(long bitfield) { int count = 0; for (short i = 0; i < Long.SIZE; i++) { if ((bitfield & 0x01) != 0) { count++; } bitfield >>>= 1; } return count; } }