I need advice how to properly convert negative fractional part to binary.
My custom data type with fixed point need be converted to byte[]
.
So, currently I need to implement such conversion:
BigDecimal -> byte[] -> BigDecimal
As I understand, fraction follows the same 2's complement
form as an integer part, right?
How one can distinquish "plain -1" from negative fraction?
Short generic case example would be very usefull.
How one will write -1.375 and -0.375 in binary ?
I think you can code as (updated):
Convert to byte[]
Convert from byte[]
Note: probably you would like to save
BigDecimal
array length.