Here you can find the source of intToByteArray(int l)
Parameter | Description |
---|---|
l | the integer to convert |
private static byte[] intToByteArray(int l)
//package com.java2s; /*//from w ww .j a v a 2s . c o m * This file is part of "Tweety", a collection of Java libraries for * logical aspects of artificial intelligence and knowledge representation. * * Tweety is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.nio.IntBuffer; import java.nio.ByteBuffer; public class Main { /** * Converts an {@code int} to a {@code byte} array of length 4 containing the integer encoded in two's complement. * @param l the integer to convert * @return the resulting {@code byte} array */ private static byte[] intToByteArray(int l) { byte[] bArray = new byte[4]; ByteBuffer bBuffer = ByteBuffer.wrap(bArray); IntBuffer iBuffer = bBuffer.asIntBuffer(); iBuffer.put(0, l); return bArray; } }