Java: Convert from BigInteger to byte
Use Number.byteValue
:
BigInteger bigInt = ...
byte b = bigInt.byteValue()
Note that this simply discards all but the lowest 8 bits. If the BigInteger
is outside of the range −128…127 the conversion my have unexpected results.
BigInteger | byteValue() |
---|---|
100 | 100 |
127 | 127 |
128 | −128 |
129 | −127 |
256 | 0 |
1,000 | −24 |
−1,000 | 24 |
Comments
Be the first to comment!