Java Hash Calculate hash(boolean[] array)

Here you can find the source of hash(boolean[] array)

Description

hash

License

Open Source License

Declaration

public static int hash(boolean[] array) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by                            /

public class Main {
    public static int hash(boolean[] array) {
        if (array.length == 4) {
            if (!array[0] && !array[1] && !array[2] && !array[3]) {
                return 0;
            }//from   ww  w. ja va 2  s  . com
            return ((array[0] ? 1 : 0) << 3) + ((array[1] ? 1 : 0) << 2)
                    + ((array[2] ? 1 : 0) << 1) + (array[3] ? 1 : 0);
        }
        int n = 0;
        for (int j = 0; j < array.length; ++j) {
            n = (n << 1) + (array[j] ? 1 : 0);
        }
        return n;
    }
}

Related

  1. getHashString(String password, String salt)
  2. getHashWithSalt(String input, String algorithm, String salt)
  3. hash()
  4. hash(Boolean value)
  5. hash(boolean value, int seed)
  6. hash(byte x)
  7. hash(byte[] bytes)
  8. hash(byte[] bytes)
  9. hash(byte[] data)