com.github.fosin.cdp.util.ByteUtil Maven / Gradle / Ivy
package com.github.fosin.cdp.util;
/**
* Created by jimin on 15/12/11.
*
* @author 28860823
* @version $Id: $
*/
public class ByteUtil {
/**
* toByteArray
*
* @param l a {@link java.lang.Long} object.
* @return an array of byte.
*/
public static byte[] toByteArray(Long l) {
byte[] b = new byte[8];
for (int i = 0; i < b.length; ++i) {
b[7 - i] = (byte) ((int) (l.longValue() >>> i * 8));
}
return b;
}
/**
* toByteArray
*
* @param i a {@link java.lang.Integer} object.
* @return an array of byte.
*/
public static byte[] toByteArray(Integer i) {
byte[] b = new byte[4];
for (int j = 0; j < 4; ++j) {
b[3 - j] = (byte) (i.intValue() >>> j * 8);
}
return b;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy