Java Number Swap swapDouble(double value)

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

Description

Reverses the byte order of the source double value

License

Apache License

Parameter

Parameter Description
value the source value

Return

the converted value

Declaration

public static double swapDouble(double value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*www .j a  v  a2 s.  co  m*/
     * Reverses the byte order of the source <tt>double</tt> value
     * @param value the source value
     * @return the converted value
     */
    public static double swapDouble(double value) {
        long l = Double.doubleToLongBits(value);
        l = swapLong(l);
        return Double.longBitsToDouble(l);
    }

    /**
     * Reverses the byte order of the source <tt>long</tt> value
     * @param value the source value
     * @return the converted value
     */
    public static long swapLong(long value) {
        return ((value & 0xFF00000000000000L) >> 56) | ((value & 0x00FF000000000000L) >> 40)
                | ((value & 0x0000FF0000000000L) >> 24) | ((value & 0x000000FF00000000L) >> 8)
                | ((value & 0x00000000FF000000L) << 8) | ((value & 0x0000000000FF0000L) << 24)
                | ((value & 0x000000000000FF00L) << 40) | ((value & 0x00000000000000FFL) << 56);
    }
}

Related

  1. swapBits(byte in)
  2. swapBits(int b, int i, int j)
  3. swapByte(byte b)
  4. swapBytes(final int i)
  5. swapCasing(String str)
  6. swapDouble(double value)
  7. swapFloat(float floatValue)
  8. swapFloat(float value)
  9. swapInt(int i)