Converting 32-bit unsigned integer (big endian) to long and back
问题 I have a byte[4] which contains a 32-bit unsigned integer (in big endian order) and I need to convert it to long (as int can't hold an unsigned number). Also, how do I do it vice-versa (i.e. from long that contains a 32-bit unsigned integer to byte[4])? 回答1: Sounds like a work for the ByteBuffer. Somewhat like public static void main(String[] args) { byte[] payload = toArray(-1991249); int number = fromArray(payload); System.out.println(number); } public static int fromArray(byte[] payload){