求助,急,压缩的BCD码转换为十进制数或着是ascii码 地磅中读出的数据是压缩的bcd码,请教如何转换为十进制或者是ascii码.最后能有示例程序.谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ///////////////////////////////////////////////////////// 107.// 108.// 功能: BCD 转 10 进制 109.// 110.// 输入: const unsigned char *bcd 待转换的 BCD 码 111.// int length BCD 码数据长度 112.// 113.// 输出: 114.// 115.// 返回: unsigned long 当前数据位的权 116.// 117.// 思路:压缩 BCD 码一个字符所表示的十进制数据范围为 0 ~ 99, 进制为 100 118.// 先求每个字符所表示的十进制值,然后乘以权 119.////////////////////////////////////////////////////////// 120.unsigned long BCDtoDec(const unsigned char *bcd, int length) 121.{ 122. int i, tmp; 123. unsigned long dec = 0; 124. 125. for(i=0; i<length; i++) 126. { 127. tmp = ((bcd[i]>>4)&0x0F)*10 + (bcd[i]&0x0F); 128. dec += tmp * power(100, length-1-i); 129. } 130. 131. return dec; 132.}本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lenyusun/archive/2010/03/05/5350143.aspx unsigned char Hundreds,Tens,Ones; void DecimalToBcdAscii(signed short DecimalValue) { Hundreds = 0; // Initialize BCD values Tens = 0; Ones = 0; Hundreds: // Hundreds DecimalValue = DecimalValue - 100; if (DecimalValue 0) { goto Tens1; } Hundreds = Hundreds + 1; // Increment Hundreds count goto Hundreds; Tens1: // Tens DecimalValue = DecimalValue + 100; Tens2: DecimalValue = DecimalValue - 10; if (DecimalValue 0) { goto Ones1; } Tens = Tens + 1; // Increment Tens count goto Tens2; Ones1: // Ones DecimalValue = DecimalValue + 10; Ones2: DecimalValue = DecimalValue - 1; if (DecimalValue 0) { goto AddAsciiOffset; } Ones = Ones + 1; // Increment Ones count goto Ones2; AddAsciiOffset: // Add ASCII offset Hundreds = Hundreds + 48; Tens = Tens + 48; Ones = Ones + 48; } RichEdit报错! 急!!!为什么dbgrideh的footer不能汇总值,怎样控制在 里面录入数据时不能输两个小数点,各位请帮忙! 释放Automation内动态创建的Query 用ttcpClient组件接收数据的问题 那里fastreport中文版有吗?急啊,等着救命! 在DELPHI中如何调用SQL SERVER的存储函数? 关于Delphi数据库的问题??????? 取随机纪录的问题 delphi的朋友请帮一个忙 关于JPEG的问题???? dbgrideh复选框如何默认不选中? fastreport 如何设置 连续打印相同几份报表再打印下份报表!
107.//
108.// 功能: BCD 转 10 进制
109.//
110.// 输入: const unsigned char *bcd 待转换的 BCD 码
111.// int length BCD 码数据长度
112.//
113.// 输出:
114.//
115.// 返回: unsigned long 当前数据位的权
116.//
117.// 思路:压缩 BCD 码一个字符所表示的十进制数据范围为 0 ~ 99, 进制为 100
118.// 先求每个字符所表示的十进制值,然后乘以权
119.//////////////////////////////////////////////////////////
120.unsigned long BCDtoDec(const unsigned char *bcd, int length)
121.{
122. int i, tmp;
123. unsigned long dec = 0;
124.
125. for(i=0; i<length; i++)
126. {
127. tmp = ((bcd[i]>>4)&0x0F)*10 + (bcd[i]&0x0F);
128. dec += tmp * power(100, length-1-i);
129. }
130.
131. return dec;
132.}本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lenyusun/archive/2010/03/05/5350143.aspx
void DecimalToBcdAscii(signed short DecimalValue)
{
Hundreds = 0; // Initialize BCD values
Tens = 0;
Ones = 0;
Hundreds: // Hundreds
DecimalValue = DecimalValue - 100;
if (DecimalValue 0)
{
goto Tens1;
}
Hundreds = Hundreds + 1; // Increment Hundreds count
goto Hundreds;
Tens1: // Tens
DecimalValue = DecimalValue + 100;
Tens2:
DecimalValue = DecimalValue - 10;
if (DecimalValue 0)
{
goto Ones1;
}
Tens = Tens + 1; // Increment Tens count
goto Tens2;
Ones1: // Ones
DecimalValue = DecimalValue + 10;
Ones2:
DecimalValue = DecimalValue - 1;
if (DecimalValue 0)
{
goto AddAsciiOffset;
}
Ones = Ones + 1; // Increment Ones count
goto Ones2;
AddAsciiOffset: // Add ASCII offset
Hundreds = Hundreds + 48;
Tens = Tens + 48;
Ones = Ones + 48;
}