All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kr.pe.kwonnam.hibernate4memcached.util.IntToBytesUtils Maven / Gradle / Ivy

There is a newer version: 0.7
Show newest version
package kr.pe.kwonnam.hibernate4memcached.util;

/**
 * @author KwonNam Son ([email protected])
 */
public class IntToBytesUtils {

    /**
     * int value to 4 bytes array.
     */
    public static byte[] intToBytes(int value) {
        return new byte[]{(byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) (value)

        };
    }

    /**
     * 4 bytes array to int
     */
    public static int bytesToInt(byte[] bytes) {
        int value = ((int) bytes[0] & 0xFF) << 24;
        value += ((int) bytes[1] & 0xFF) << 16;
        value += ((int) bytes[2] & 0xFF) << 8;
        value += (int) bytes[3] & 0xFF;
        return value;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy