Java Byte Array Create toBytes(int data)

Here you can find the source of toBytes(int data)

Description

to Bytes

License

Apache License

Declaration

public static byte[] toBytes(int data) 

Method Source Code

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

public class Main {
    public static byte[] toBytes(int data) {
        return new byte[] { (byte) (data >> 24), (byte) (data >> 16), (byte) (data >> 8), (byte) (data) };
    }//from   w  w  w. j  a  va  2 s  . c o m

    public static byte[] toBytes(short data) {
        return new byte[] { (byte) (data >> 8), (byte) (data) };
    }

    public static byte[] toBytes(long data) {
        return new byte[] { (byte) (data >> 56), (byte) (data >> 48), (byte) (data >> 40), (byte) (data >> 32),
                (byte) (data >> 24), (byte) (data >> 16), (byte) (data >> 8), (byte) (data) };
    }

    public static byte[] toBytes(double data) {
        long l = Double.doubleToRawLongBits(data);
        return toBytes(l);
    }
}

Related

  1. toBytes(final long n)
  2. toBytes(final long val)
  3. toBytes(final String hexaString)
  4. toBytes(final String str)
  5. toBytes(final String text)
  6. toBytes(int data)
  7. toBytes(int i)
  8. toBytes(int i)
  9. toBytes(int i)