Java Zero Format zerocount(int v)

Here you can find the source of zerocount(int v)

Description

Return the number of zeros in the binary representation of the value of the argument.

License

GNU General Public License

Declaration

public static final int zerocount(int v) 

Method Source Code

//package com.java2s;
// Licensed under the terms of the GNU GPL; see COPYING for details.

public class Main {
    /** Number of zeros in a byte. */
    static final byte bytezeros[] = { 8, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4, 7, 6, 6, 5, 6, 5, 5, 4, 6, 5,
            5, 4, 5, 4, 4, 3, 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4,
            3, 3, 2, 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2,
            6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 7, 6, 6,
            5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, 6, 5, 5, 4, 5, 4,
            4, 3, 5, 4, 4, 3, 4, 3, 3, 2, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 6, 5, 5, 4, 5, 4, 4, 3, 5,
            4, 4, 3, 4, 3, 3, 2, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2,
            3, 2, 2, 1, 4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0 };

    /** Return the number of zeros in the binary representation of the
     *  value of the argument. */
    public static final int zerocount(int v) {
        return bytezeros[v & 0xFF] + bytezeros[(v >> 8) & 0xFF] + bytezeros[(v >> 16) & 0xFF]
                + bytezeros[(v >> 24) & 0xFF];
    }//from www . ja  v a 2s .c  o m

    /** Return the number of zeros in the binary representation of the
     *  value of the argument. */
    public static final int zerocount(long v) {
        return zerocount((int) v) + zerocount((int) (v >> 32));
    }
}

Related

  1. zero_pad(byte[] original, int block_size)
  2. zeroAlign(String x, int count)
  3. zeroBasedTemplateStart(final int[] actions)
  4. zeroBlock(byte[] block, int off, int len)
  5. zeroConvert(String src)
  6. zeroCount(long n)
  7. zeroDiv(double numerator, double denominator)
  8. zeroes(final int ch)
  9. zeroEsquerda(String s1, int tamString)