Java Hash Calculate calculateHash(String str)

Here you can find the source of calculateHash(String str)

Description

Calculates Hash.

License

MIT License

Parameter

Parameter Description
str String to hash.

Return

hash.

Declaration

static public String calculateHash(String str) 

Method Source Code

//package com.java2s;
/**//from  ww  w . j  a v a 2  s .  c  o  m
 *   Copyright © 2008-2012 NetAllied Systems GmbH, Ravensburg, Germany. 
 *       
 *   Licensed under the MIT Open Source License, 
 *   for details please see LICENSE file or the website
 *   http://www.opensource.org/licenses/mit-license.php
*/

public class Main {
    /**
     * Calculates Hash.
     * 
     * @param str
     *            String to hash.
     * @return hash.
     */
    static public String calculateHash(String str) {
        long h = 0;
        long g;
        int pos = 0;

        while (pos < str.length()) {
            h = (h << 4) + str.charAt(pos++);
            if ((g = (h & 0xf0000000)) != 0)
                h ^= g >> 24;
            h &= ~g;
        }
        return String.valueOf(h);
    }
}

Related

  1. calculateHash(int x, int y)
  2. calculateHash(Long... ids)
  3. calculateHashCode(byte a[])
  4. getHash(byte[] bytes)
  5. getHash(byte[] bytes)
  6. getHash(byte[] data)