Java Double to doubleToHashString(double value)

Here you can find the source of doubleToHashString(double value)

Description

double To Hash String

License

Apache License

Declaration

public static String doubleToHashString(double value) 

Method Source Code

//package com.java2s;
/*/*  w w w .ja v a  2  s  .  co m*/
 * Copyright 2017 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    private static final char[] HEX_CHARACTERS = "0123456789abcdef".toCharArray();

    public static String doubleToHashString(double value) {
        StringBuilder sb = new StringBuilder(16);
        long bits = Double.doubleToLongBits(value);
        // We use big-endian to encode the bytes
        for (int i = 7; i >= 0; i--) {
            int byteValue = (int) ((bits >>> (8 * i)) & 0xff);
            int high = ((byteValue >> 4) & 0xf);
            int low = (byteValue & 0xf);
            sb.append(HEX_CHARACTERS[high]);
            sb.append(HEX_CHARACTERS[low]);
        }
        return sb.toString();
    }
}

Related

  1. doubleToDoubleArray(double... a)
  2. doubleToFloatArray(double[] dArray)
  3. doubleToFloatArray(double[] doubles)
  4. doubleToFloatMatrix(double[][] matrix)
  5. doubleToFractionStr(final Double d)
  6. doubleToHexString(double val)
  7. doubleToI18nString(double d)
  8. doubleToIndex(final double x)
  9. doubleToLex(double v)