500分给知道BCD码的资料,最好有C语言代码!急用!!!
我急用BCD编码,最好有C语言代码示例,
比如2002年用2字节,11月用1字节,25日用1字节,用BCD码表示
问题点数:100、回复次数:3Top
1 楼rovoboy(魂之猎人)回复于 2002-03-27 10:15:02 得分 100
要不要我给你写一个?
有什么要求?明确点。Top
2 楼rovoboy(魂之猎人)回复于 2002-03-27 17:34:18 得分 0
虽然简陋了点,不过你的要求应该可以了。本来做成类更好。
// BCD.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
typedef unsigned long DWORD;
typedef unsigned char BYTE;
typedef unsigned short WORD;
BYTE BCD(int &Num)
{
int i;
i=Num%10;
Num/=10;
return i;
}
//适用数字范围0~99
BYTE ByteBCD(const int Num)
{
int i;
i=Num;
return BCD(i)
| BCD(i) << 4;
}
//适用数字范围0~9999
WORD WordBCD(const int Num)
{
int i;
i=Num;
return BCD(i)
| BCD(i) << 4
| BCD(i) << 8
| BCD(i) << 12;
}
//适用数字范围0~99999999
DWORD DWordBCD(const int Num)
{
int i;
i=Num;
return BCD(i)
| BCD(i) << 4
| BCD(i) << 8
| BCD(i) << 12
| BCD(i) << 16
| BCD(i) << 20
| BCD(i) << 24
| BCD(i) << 28
| BCD(i) << 32;
}
int main(int argc, char* argv[])
{
DWORD Date;
BYTE Day,Month;
WORD Year;
Day=ByteBCD(11);
Month=ByteBCD(25);
Year=WordBCD(2002);
Date=Day | Month<<8 | Year<<16;
printf("%x\n",Date);
return 0;
}
Top
3 楼whn(whn)回复于 2002-03-28 08:45:01 得分 0
Thank you ,收到分了吗,我早给了Top




