Here you can find the source of toBigEndianBytes(int x)
public static byte[] toBigEndianBytes(int x)
//package com.java2s; /*/* w w w . j a v a 2 s . c om*/ * Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License, Version 1.0, and under the Eclipse Public License, Version 1.0 (http://h2database.com/html/license.html). Initial Developer: H2 Group */ public class Main { public static byte[] toBigEndianBytes(long x) { byte[] arr = new byte[8]; for (int i = 0; i < arr.length; i++) { arr[i] = (byte) (x >>> (64 - (i + 1) * 8)); } return arr; } public static byte[] toBigEndianBytes(int x) { return new byte[] { (byte) (x >>> 24), (byte) (x >>> 16), (byte) (x >>> 8), (byte) x }; } public static byte[] toBigEndianBytes(short x) { return new byte[] { (byte) (x >>> 8), (byte) x }; } }