public static byte[] encodeInteger(BigInteger x) { if (x < 0) { throw new ArgumentException("x cannot be negative"); } string t = x.ToString("X"); if (t.Length % 2 == 1) { t = "0" + t; } byte[] xBytes = BinaryAscii.binaryFromHex(t); int num = xBytes[0]; if (num <= hex127) { return(combineByteArrays(new List <byte[]> { bytesHexB, Bytes.intToCharBytes(xBytes.Length), xBytes })); } return(combineByteArrays(new List <byte[]> { bytesHexB, Bytes.intToCharBytes(xBytes.Length + 1), bytesHexAt, xBytes })); }
private static byte[] encodeLength(int length) { if (length < 0) { throw new ArgumentException("length cannot be negative"); } if (length < hex128) { return(Bytes.intToCharBytes(length)); } string s = length.ToString("X"); if ((s.Length % 2) == 1) { s = "0" + s; } byte[] bytes = BinaryAscii.binaryFromHex(s); int lengthLen = bytes.Length; return(combineByteArrays(new List <byte[]> { Bytes.intToCharBytes(hex128 | lengthLen), bytes })); }