bool AtoBCD(unsigned char* Asc,unsigned char* BCD,int len)
{
int i;
unsigned char ch; //高位
unsigned char cl; //低位
unsigned char temp1;
unsigned char temp2;
unsigned char *Retrun;

Retrun = new unsigned char[len/2+1];

memset(Retrun,0,len/2+1);

for (i=0;i<len/2;i++)
{
temp1 = Asc[2*i]; //高位
temp2 = Asc[2*i+1]; //低位

if ((temp1 >= 'A' && temp1 <= 'F') || (temp1 >='a' && temp1 <= 'f'))
{
ch = (((temp1 -7) & 0x0f)<<4) & 0xff;
}
else if(temp1 >= '0' && temp1 <= '9')
{
ch = ((temp1 & 0x0f)<<4) & 0xff;
}
else
{
return false;
}

//*************************************************************************//

if ((temp2 >= 'A' && temp2 <= 'F') || (temp2 >= 'a' && temp2 <= 'f'))
{
cl = ((temp2 -7) & 0x0f) & 0xff;
}
else if(temp2 >= '0' && temp2 <= '9')
{
cl = (temp2 & 0x0f) & 0xff;
}
else
{
return false;
}

Retrun[i] = ch | cl;
}

memcpy(BCD,Retrun,len/2);
delete []Retrun;

return true;
}

unsigned char *BCDtoA( unsigned char * Data, int Len)
{
int i,j;
unsigned char temp1,temp2;
unsigned char ptr[500];
unsigned char *Ptr;
j=0;

for(i=0;i<Len;i++)
{
temp1=Data[i];
temp2=temp1 & 0x0f ;
if ((temp2>=0x00) && (temp2<=0x09))
{
ptr[i*2+1]=temp2+0x30;
}
else
{
if(temp2==10)
ptr[i*2+1]='A';
else if(temp2==11)
ptr[i*2+1]='B';
else if(temp2==12)
ptr[i*2+1]='C';
else if(temp2==13)
ptr[i*2+1]='D';
else if(temp2==14)
ptr[i*2+1]='E';
else if(temp2==15)
ptr[i*2+1]='F';
}

temp1=Data[i];
temp2=temp1>>4 ;
temp2=temp2 & 0x0f ;

if ((temp2>=0x00) && (temp2<=0x09))
{
ptr[i*2]=temp2+0x30;
}
else
{
if(temp2==10)
ptr[i*2]='A';
else if(temp2==11)
ptr[i*2]='B';
else if(temp2==12)
ptr[i*2]='C';
else if(temp2==13)
ptr[i*2]='D';
else if(temp2==14)
ptr[i*2]='E';
else if(temp2==15)
ptr[i*2]='F';

}
}
Ptr = ptr;
return( Ptr );
}

最新文章

  1. Android—基于微信开放平台v3SDK,开发微信支付填坑。
  2. bzoj1588
  3. JMeter学习-010-JMeter 配置元件实例之 - CSV Data Set Config 参数化配置
  4. Java--&gt;分割文件
  5. 解决 border-radius 元素在应用了 transform 的子元素 时overflow:hidden 失效的问题
  6. WCf的理解
  7. Linux 下安装配置nginx及常见问题解答
  8. 《University Calculus》-chape4-导数的应用-洛必达法则
  9. JAXP的SAX解析
  10. 64位win2003 IIS6运行32位的.NET程序
  11. 作业03-面向对象入门.md
  12. MongoDB学习(操作集合中的文档)
  13. html5与css3面试题(2)
  14. Spring Boot+Spring Security:获取用户信息和session并发控制
  15. html缓存控制
  16. 从cpu负载到jstack分析线程状态
  17. 20145216史婧瑶《Java程序设计》第3周学习总结
  18. 定时器Quartz ClassNotFound org.springframework.scheduling.quartz.SchedulerFactoryBean
  19. python中完善decorator
  20. wiredtiger引擎性能——比levelDB更牛叉!

热门文章

  1. Kinect 开发 —— 常见手势识别(下)
  2. tcp为什么要三次握手
  3. 关于IDEA编译器在初次使用thymeleaf 引入无效 , 导致th无法使用的原因
  4. 【2017 Multi-University Training Contest - Team 4】Time To Get Up
  5. BZOJ——T 1355: [Baltic2009]Radio Transmission
  6. https://github.com/ 英文库
  7. Python-根据成绩分析是否继续深造
  8. Java学习笔记九
  9. BZOJ1576: [Usaco2009 Jan]安全路经Travel(树链剖分)
  10. Linux登录状态