Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static byte[] intToBytes(int n) {
- byte[] b = new byte[4];
- for(int i=0; i<4; i++)
- b[i] = (byte) (n >>> 8*i);
- return b;
- }
- public static int bytesToInt(byte[] bytes) {
- int n = 0;
- for (int i=0; i<4 && i<bytes.length; i++) {
- n += ((int)bytes[i] & 0xFF) << 8*i;
- }
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement