code: public static byte[] encodeUnsignedLong(long value) {
          if (value < 0) {
              throw new IllegalArgumentException("Only non-negative integer values are allowed");
          }
          int n = 0;
          for (long t = value; t > 0; t >>>= 8) {
              ++n;
          }
          byte[] res = new byte[n];
          for (long t = value; t > 0; t >>>= 8) {
              res[--n] = (byte) t;
          }
          return res;
      }
docs: Encodes the given value in a minimal number of bytes, in network byte order (most significant bits first).
  
  @param value
  the value to encode (the encoding is unsigned, so only non-negative values are supported).
  
  @return A newly allocated array containing the encoding result.