public Byte[] ToByteArray() {
Int32 n = this._wordsInUse;
if (n == 0) {
return new Byte[0];
}
Int32 len = 8 * (n - 1);
for (long x = this._bits[n - 1]; x != 0; x >>= 8) {
len++;
}
Byte[] bytes = new Byte[len];
using (MemoryStream ms = new MemoryStream(bytes)) {
using (BinaryWriter writer = new BinaryWriter(ms)) {
for (Int32 i = 0; i < n - 1; i++) {
writer.Write(this._bits[i]);
}
for (long x = this._bits[n - 1]; x != 0L; x >>= 8) {
writer.Write((Byte)(x & 0xff));
}
}
}
return bytes;
}