Re: BCD-Decimal

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Wed, 18 Jul 2007 14:10:10 -0400, "Stephen" <nospam@xxxxxxxxx>
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

.



Relevant Pages

  • Re: Currency Rounding Errors
    ... If you want to stop at that precision. ... What I did was my own Number class, that stored the digits in an array, ... The x86 is the first machine in history to waste 5 of the bits of the byte to create BCD. ... bytes and do weird instructions such as ADD followed by AAA, ...
    (microsoft.public.vc.mfc)
  • RE: generating a wordlist from an array of arrays
    ... generating a wordlist from an array of arrays ...
    (perl.beginners)
  • Re: Currency Rounding Errors
    ... If you want to stop at that precision. ... What I did was my own Number class, that stored the digits in an array, ... So BCD was not enough. ... There's a whole bunch of such funny instructions such as ...
    (microsoft.public.vc.mfc)
  • Re: How to instantaneously convert array of Integers into an array on ints?
    ... rossum wrote: ... into primitive *int* array. ... scope of n is more restricted restricted so may help the compiler. ... The length of an array can not vary. ...
    (comp.lang.java.programmer)
  • Binary Coded Decimal (BCD) how to convert???
    ... notation) and send it to ... network resource. ... how can i convert the int value to bcd an store this ...
    (microsoft.public.dotnet.languages.csharp)