Java Bits Convert to bitHistogram(int[] data)

Here you can find the source of bitHistogram(int[] data)

Description

Make a histogram of bit number from a given sample of ints.

License

Open Source License

Parameter

Parameter Description
data is the int sample

Return

an int[32] array in which each value is the number of times that bit was present

Declaration

public static int[] bitHistogram(int[] data) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w  w  w .j  av  a 2  s . c om
     * Make a histogram of bit number from a given sample of ints.
     * @param data is the int sample
     * @return an int[32] array in which each value is the number of times that bit was present
     */
    public static int[] bitHistogram(int[] data) {
        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;
    }
}

Related

  1. bitch(Throwable t)
  2. bitFieldToIndexArray(long bitfield)
  3. bitFieldToString(boolean[] bits)
  4. bitfieldToString(String[] statenames, int value)
  5. bitFlagByteLength(final int nbits)
  6. 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)
  7. bitmap64(byte... table)
  8. BitPrecisionInt(int numberValue)
  9. bitRangeValueLong(byte[] b, int offset, int length)