Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.nio.ByteBuffer;

public class Main {
    /**
     * convert int to byte array
     * 
     * @param value
     *            integer value
     * @return byte array
     */
    public static byte[] convertIntToByte(int value) {
        byte[] temp = new byte[4];
        byte[] result = ByteBuffer.allocate(4).putInt(value).array();
        temp[0] = result[3];
        temp[1] = result[2];
        temp[2] = result[1];
        temp[3] = result[0];
        return temp;
    }
}