Here you can find the source of toByteArrayBE(byte b)
public static byte[] toByteArrayBE(byte b)
//package com.java2s; /*-/*from w w w . j a v a 2 s. c om*/ * Copyright (C) 2006-2007 Erik Larsson * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 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/>. */ public class Main { public static byte[] toByteArrayBE(byte b) { byte[] result = new byte[1]; result[0] = b; return result; } public static byte[] toByteArrayBE(short s) { byte[] result = new byte[2]; result[0] = (byte) ((s >> 8) & 0xFF); result[1] = (byte) ((s >> 0) & 0xFF); return result; } public static byte[] toByteArrayBE(char c) { byte[] result = new byte[2]; result[0] = (byte) ((c >> 8) & 0xFF); result[1] = (byte) ((c >> 0) & 0xFF); return result; } public static byte[] toByteArrayBE(int i) { byte[] result = new byte[4]; result[0] = (byte) ((i >> 24) & 0xFF); result[1] = (byte) ((i >> 16) & 0xFF); result[2] = (byte) ((i >> 8) & 0xFF); result[3] = (byte) ((i >> 0) & 0xFF); return result; } public static byte[] toByteArrayBE(long l) { byte[] result = new byte[8]; result[0] = (byte) ((l >> 56) & 0xFF); result[1] = (byte) ((l >> 48) & 0xFF); result[2] = (byte) ((l >> 40) & 0xFF); result[3] = (byte) ((l >> 32) & 0xFF); result[4] = (byte) ((l >> 24) & 0xFF); result[5] = (byte) ((l >> 16) & 0xFF); result[6] = (byte) ((l >> 8) & 0xFF); result[7] = (byte) ((l >> 0) & 0xFF); return result; } }