On Wed, 18 Jul 2007 14:10:10 -0400, "Stephen" <no****@nospam.no>
wrote:
>What I was really looking for was a solution that would allow for a binary
number encoded in BCD to be converted to decimal. Eg
10000 11001 = 1 3
Do you mean 0001 0011 -1 3?
How is your BCD number held, as a byte array or what?
How do you want the decimal equivalent, as a string, int, long, double
or what?
Here is some example code to convert BCD held in a big-endian byte
array to a long:
long BCD2Long(byte source) {
long result = 0;
foreach (byte b in source) {
int hi = b >4;
int lo = b & 0x0F;
result *= 10;
result += hi;
result *= 10;
result += lo;
}
return result;
}
Warning, neither tested nor compiled. Caveat emptor.
rossum