Decimal Representation, with a 64bit mantissa and an 8bit exponent
Posted on 2009-05-28
I'm working on a project where we need to generate a byte stream of Dec64 with an 8bit exponent, and send via TCP/IP. The first 8 bytes are the mantissa and the 9th byte is the exponent (which is base 10) (for the techies, this is being done in C# .NET 2.0). So in practice, we're actually sending a signed 64 bit int for the mantissa, and a signed 8 bit int for the exponent.
As an example, say we have the decimal value 123.45. The mantissa we'll be sending is a signed 64bit int of 0x3039 and the exponent is a signed 8bit int of 0xFE. On the wire, we transmit the following
Bytes: 0x39 0x30 0x00 0x00 0x00 0x00 0x00 0x00 0xFE
Binary: 00111001 00110000 00000000 00000000 00000000 00000000 00000000 00000000 11111110
So what I'm looking for is either a) the formula for taking a decimal value and converting it to a signed 64 mantissa and a signed 8 bit exponent or b) some c# code that can do this.