How can I convert a positive float (ieee 754, single precision 32 bit) to BCD in C#?
UPDATE
If I'm not wrong, what I need is called packed BCD. I'm already doing int to BCD conversions. In the way I'm doing, the number 1234 would result in the following byte array:
{0x00, 0x00, 0x12, 0x34}
The method I use (which probably isn't the best way of doing it) is:
public byte[] ToBCD(long num) {
long bcd = 0;
int i = 0;
while (num > 9) {
bcd |= ((num % 10) << i);
num /= 10;
i += 4;
}
byte[] bytes = BitConverter.GetBytes(bcd | (num << i));
Array.Reverse(bytes);
return bytes;
}