code: public static byte[] toBytes(long value, int length) {
          if (length <= 0) return new byte[0];
          if (length > 8) length = 8;
          byte[] out = new byte[length];
          for (int i = length - 1; i >= 0; i--){
              out[i] = (byte)(value & 0xFFL);
              value = value >> 8;
          }
          return out;
      }
docs: Convert a long to a byte array.
  @param value The long to convert.
  @param length The number of bytes to convert to. This allows for the conversion of shorts and ints.
  @return The converted long as a byte array.