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])?
Guava has useful classes for dealing with unsigned numeric values.
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/primitives/UnsignedInts.html#toLong(int)
Sounds like a work for the ByteBuffer.
Somewhat like
You can use ByteBuffer, or you can do it the old-fashioned way: