Advertisement
SnowyCoder

Variable length number

Jan 14th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.29 KB | None | 0 0
  1. private static long toLong(byte[] value) {
  2.     ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
  3.     final byte val = (byte) (value[0] < 0 ? 0xFF : 0);
  4.  
  5.     for(int i = value.length; i < Long.BYTES; i++)
  6.         buffer.put(val);
  7.  
  8.     buffer.put(value);
  9.     return buffer.getLong(0);
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement