Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

public class Main {
    public static byte[] intsToBytes(int[] ints) {
        int len = ints.length;
        byte[] bytes = new byte[len * 4];
        for (int i = 0; i < len; i++) {
            byte[] b = intToBytes(ints[i]);
            System.arraycopy(b, 0, bytes, i * 4, 4);
        }
        return bytes;
    }

    public static byte[] intsToBytes(List<Integer> ints) {
        int[] array = new int[ints.size()];
        for (int i = 0; i < ints.size(); i++) {
            array[i] = ints.get(i);
        }
        return intsToBytes(array);
    }

    public static byte[] intToBytes(int i) {
        byte[] bytes = new byte[4];
        bytes[0] = (byte) (i & 0xFF);
        bytes[1] = (byte) (i >>> 8 & 0xFF);
        bytes[2] = (byte) (i >>> 16 & 0xFF);
        bytes[3] = (byte) (i >>> 24 & 0xFF);
        return bytes;
    }
}