Re: BCD-Decimal
- From: rossum <rossum48@xxxxxxxxxxxx>
- Date: Wed, 18 Jul 2007 21:42:47 +0100
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 binaryDo you mean 0001 0011 -> 1 3?
number encoded in BCD to be converted to decimal. Eg
10000 11001 = 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
.
- References:
- BCD-Decimal
- From: Stephen
- Re: BCD-Decimal
- From: Alberto Poblacion
- Re: BCD-Decimal
- From: Stephen
- BCD-Decimal
- Prev by Date: TypeConverter for a PropertyGrid
- Next by Date: Re: Datetime Question
- Previous by thread: Re: BCD-Decimal
- Next by thread: Calling non-static methods from within static methods.
- Index(es):
Relevant Pages
|