Java Double to Byte doubleToByte(double d)

Here you can find the source of doubleToByte(double d)

Description

double To Byte

License

Apache License

Declaration

public static byte[] doubleToByte(double d) 

Method Source Code

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

public class Main {
    public static byte[] doubleToByte(double d) {
        long x = Double.doubleToLongBits(d);
        if ((x & 0xFFFFFFFFFFFFFF00L) == 0L) {
            return new byte[] { (byte) x };
        } else if ((x & 0xFFFFFFFFFFFF0000L) == 0L) {
            return new byte[] { (byte) (x >> 8), (byte) x };
        } else if ((x & 0xFFFFFFFFFF000000L) == 0L) {
            return new byte[] { (byte) (x >> 16), (byte) (x >> 8), (byte) x };
        } else if ((x & 0xFFFFFFFF00000000L) == 0L) {
            return new byte[] { (byte) (x >> 24), (byte) (x >> 16), (byte) (x >> 8), (byte) x };
        } else if ((x & 0xFFFFFF0000000000L) == 0L) {
            return new byte[] { (byte) (x >> 32), (byte) (x >> 24), (byte) (x >> 16), (byte) (x >> 8), (byte) x };
        } else if ((x & 0xFFFF000000000000L) == 0L) {
            return new byte[] { (byte) (x >> 40), (byte) (x >> 32), (byte) (x >> 24), (byte) (x >> 16),
                    (byte) (x >> 8), (byte) x };
        } else if ((x & 0xFF00000000000000L) == 0L) {
            return new byte[] { (byte) (x >> 48), (byte) (x >> 40), (byte) (x >> 32), (byte) (x >> 24),
                    (byte) (x >> 16), (byte) (x >> 8), (byte) x };
        }/* w  ww  .ja v a 2 s  .c o  m*/
        return new byte[] { (byte) (x >> 56), (byte) (x >> 48), (byte) (x >> 40), (byte) (x >> 32),
                (byte) (x >> 24), (byte) (x >> 16), (byte) (x >> 8), (byte) x };
    }
}

Related

  1. double2byte(double d)
  2. double2byte(double d)
  3. Double2Byte(double i)
  4. doubleToByte(double d)
  5. doubleToByte(double d)
  6. doubleToByte(double i_Value)
  7. doubleToByte(double[] values)
  8. doubleToByte(final double value)