List of utility methods to do Bits Convert to
void | bitch(Throwable t) Print an error message with a cause, and the stack trace leading up to it Usually called as Util.bitch (new Throwable ("message")) StackTraceElement[] st = t.getStackTrace(); System.err.println(st[0].getClassName() + "." + st[0].getMethodName() + " (), line " + st[0].getLineNumber() + ": " + t.getMessage()); for (int i = 1; i < st.length; i++) System.err.println(" from " + st[i].getClassName() + "." + st[i].getMethodName() + " (), line " + st[i].getLineNumber()); |
short[] | bitFieldToIndexArray(long bitfield) Get the indexes of the values 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; ... |
String | bitFieldToString(boolean[] bits) Converts a bitfield into a string. String bitfield = ""; for (int i = 0; i < bits.length; ++i) { if (bits[i]) { bitfield += "1"; } else { bitfield += "0"; return bitfield; |
String | bitfieldToString(String[] statenames, int value) Given a bitfield value @p value, and an array that names each bit position, return a comma-separated string that names each bit position that is set in @p value. if ((value == 0) || (statenames == null) || (statenames.length == 0)) { return ""; StringBuilder b = new StringBuilder(); for (int statebit = 0; statebit < statenames.length; statebit++) { int statebitvalue = 1 << statebit; if ((value & statebitvalue) != 0) { b.append(statenames[statebit]); ... |
int | bitFlagByteLength(final int nbits) Return the #of bytes required to bit code the specified #of bits. return nbits / 8 + (nbits % 8 == 0 ? 0 : 1);
|
int[] | bitHistogram(int[] data) Make a histogram of bit number from a given sample of ints. int[] histogram = new int[32]; for (int i = 0; i < data.length; i++) { for (int b = 0; b < 32; b++) { histogram[b] += (1 & (data[i] >>> b)); return histogram; |
byte | bitMap(final boolean v1, final boolean v2, final boolean v3, final boolean v4, final boolean v5, final boolean v6, final boolean v7, final boolean v8) bit Map final byte r = 0; setBit(r, 0, v1); setBit(r, 1, v2); setBit(r, 2, v3); setBit(r, 3, v4); setBit(r, 4, v5); setBit(r, 5, v6); setBit(r, 6, v7); ... |
long | bitmap64(byte... table) bitmap long map = 0; for (int i = 0; i < table.length; i++) { if (table[i] != 0) { map |= (1 << i); return map; |
int | BitPrecisionInt(int numberValue) Bit Precision Int if (numberValue == 0) { return 0; int i = 32; if ((numberValue >> 16) == 0) { numberValue <<= 16; i -= 8; ... |
long | bitRangeValueLong(byte[] b, int offset, int length) Returns the value of the bits in the given range. if (length <= 0) return 0; int byteFrom = offset / 8; int byteTo = (offset + length - 1) / 8; long result = b[byteFrom] & bitFromMask[offset % 8]; for (int i = byteFrom + 1; i <= byteTo; i++) { result <<= 8; result |= b[i] & 0xff; ... |