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

org.jgroups.raft.util.IntegerHelper Maven / Gradle / Ivy

There is a newer version: 1.0.14.Final
Show newest version
package org.jgroups.raft.util;

/**
 * Created by ugol on 05/12/14.
 */
public class IntegerHelper {

    public static byte[] fromIntToByteArray(int value) {
        return new byte[] {
                (byte)(value >>> 24),
                (byte)(value >>> 16),
                (byte)(value >>> 8),
                (byte)value};
    }

    public static int fromByteArrayToInt(byte[] b) {

        if ((b == null) || (b.length != 4)) {return 0;}

        return   b[3] & 0xFF |
                (b[2] & 0xFF) << 8 |
                (b[1] & 0xFF) << 16 |
                (b[0] & 0xFF) << 24;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy