Why BigInteger ToByteArray method sometime generate an extra byte?

68 Views Asked by At

Console app :

BigInteger tst = 128;

byte[] buffer = tst.ToByteArray();

foreach (byte b in buffer)
    Console.WriteLine(b);

Console.Read();

Result :

128
0

Why BigInteger ToByteArray method sometime generate this extra byte ? I tried that on version 4.7.2 & 4.5.2 of the .Net Framework, same result. Any clue is welcome, you may need System.Numerics reference to compile this code. thx

0

There are 0 best solutions below