Java Byte Array from getBytes(byte value)

Here you can find the source of getBytes(byte value)

Description

get Bytes

License

Apache License

Declaration

public static byte[] getBytes(byte value) throws IOException 

Method Source Code

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

import java.io.IOException;

public class Main {
    public static byte[] getBytes(byte value) throws IOException {
        byte[] byteArray = new byte[1];
        byteArray[0] = value;/*from www . j  a va2  s  .c  o  m*/
        return byteArray;
    }

    public static byte[] getBytes(int value, int length) throws IOException {
        return getBytes((long) value, length);
    }

    public static byte[] getBytes(long value, int length) throws IOException {

        byte[] b = new byte[length];
        for (int i = 0; i < length; i++) {
            int offset = (b.length - 1 - i) * 8;
            b[i] = (byte) ((value >> offset) & 0xFF);
        }
        return b;
    }
}

Related

  1. getBytes(byte[] buffer, int offset)
  2. getBytes(Class clazz)
  3. getBytes(Class clazz)
  4. getBytes(Class cls, String resourceName)