code: static public int bigIntegerToBytes(BigInteger integer, byte[] buffer, int index) {
          int length = 4 + (integer.bitLength() + 8) / 8;
          System.arraycopy(intToBytes(length), 0, buffer, index, 4);  // copy in the length
          index += 4;
          System.arraycopy(integer.toByteArray(), 0, buffer, index, length - 4);  // copy in the big integer
          return length;
      }
docs: This function converts a big integer into its corresponding byte format and inserts
  it into the specified buffer at the specified index.
  
  @param integer The big integer to be converted.
  @param buffer The byte array.
  @param index The index in the array to begin inserting bytes.
  @return The number of bytes inserted.