code: private byte[] bytesForBig(BigInteger big, int sigbytes, boolean remainder)
      {
          byte[] bytes = new byte[sigbytes + (remainder ? 1 : 0)];
          if (remainder)
          {
              // remaining bit is the most significant in the last byte
              bytes[sigbytes] |= 0x80;
          }
          // bitmask for a single byte
          for (int i = 0; i < sigbytes; i++)
          {
              int maskpos = 8 * (sigbytes - (i + 1));
              // apply bitmask and get byte value
              bytes[i] = (byte)(big.and(BYTE_MASK.shiftLeft(maskpos)).shiftRight(maskpos).intValue() & 0xFF);
          }
          return bytes;
      }
docs: Convert a (positive) BigInteger into a byte array representing its magnitude.
  If remainder is true, an additional byte with the high order bit enabled
  will be added to the end of the array