List of usage examples for java.lang Byte SIZE
int SIZE
To view the source code for java.lang Byte SIZE.
Click Source Link
From source file:Main.java
public static void main(String args[]) { System.out.println("Size of a Byte:" + Byte.SIZE); }
From source file:Main.java
public static void byteToBit(byte[] bytes, StringBuilder sb) { for (int i = 0; i < Byte.SIZE * bytes.length; i++) sb.append((bytes[i / Byte.SIZE] << i % Byte.SIZE & 0x80) == 0 ? '0' : '1'); }
From source file:Main.java
public static int getMessageInfo(int messageType, byte seqType) { int info = messageType << Byte.SIZE; info |= seqType & MAX_BYTE;/*w ww . j a v a2 s. c o m*/ return info; }
From source file:Main.java
public static Short byteArrayToShort(byte[] bytes) { if (bytes.length != (Short.SIZE / Byte.SIZE)) { throw new IllegalArgumentException("Incorrect array size to convert to a short"); }/*from ww w . java2 s .c om*/ ByteBuffer buffer = ByteBuffer.wrap(bytes); buffer.order(ByteOrder.BIG_ENDIAN); return buffer.getShort(); }
From source file:Main.java
public static Short byteArrayToShortLE(byte[] bytes) { if (bytes.length != (Short.SIZE / Byte.SIZE)) { throw new IllegalArgumentException("Incorrect array size to convert to a short"); }//from www .ja v a2 s. co m ByteBuffer buffer = ByteBuffer.wrap(bytes); buffer.order(ByteOrder.LITTLE_ENDIAN); return buffer.getShort(); }
From source file:Main.java
public static byte[] intToByteArray(int value) { ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putInt(value);/*from w w w .j ava 2 s . c o m*/ return buffer.array(); }
From source file:Main.java
public static byte[] shortToByteArray(short value) { ByteBuffer buffer = ByteBuffer.allocate(Short.SIZE / Byte.SIZE); buffer.order(ByteOrder.BIG_ENDIAN); buffer.putShort(value);/*from www .j a va 2s . co m*/ return buffer.array(); }
From source file:Main.java
public static byte[] intToByteArrayLE(int value) { ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(value);//from ww w .java 2s .c o m return buffer.array(); }
From source file:Main.java
public static byte[] shortToByteArrayLE(short value) { ByteBuffer buffer = ByteBuffer.allocate(Short.SIZE / Byte.SIZE); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putShort(value);/*from www . j a v a2s . c o m*/ return buffer.array(); }
From source file:Main.java
public static int byteArrayToInt(byte[] bytes) throws IllegalArgumentException { if (bytes.length != (Integer.SIZE / Byte.SIZE)) { throw new IllegalArgumentException("Incorrect array size to convert to an int"); }//from ww w . j a v a 2 s.c o m ByteBuffer buffer = ByteBuffer.wrap(bytes); buffer.order(ByteOrder.BIG_ENDIAN); return buffer.getInt(); }