ANSCII码和BCD码互转
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 );
}
最新文章
- Android—基于微信开放平台v3SDK,开发微信支付填坑。
- bzoj1588
- JMeter学习-010-JMeter 配置元件实例之 - CSV Data Set Config 参数化配置
- Java-->;分割文件
- 解决 border-radius 元素在应用了 transform 的子元素 时overflow:hidden 失效的问题
- WCf的理解
- Linux 下安装配置nginx及常见问题解答
- 《University Calculus》-chape4-导数的应用-洛必达法则
- JAXP的SAX解析
- 64位win2003 IIS6运行32位的.NET程序
- 作业03-面向对象入门.md
- MongoDB学习(操作集合中的文档)
- html5与css3面试题(2)
- Spring Boot+Spring Security:获取用户信息和session并发控制
- html缓存控制
- 从cpu负载到jstack分析线程状态
- 20145216史婧瑶《Java程序设计》第3周学习总结
- 定时器Quartz ClassNotFound org.springframework.scheduling.quartz.SchedulerFactoryBean
- python中完善decorator
- wiredtiger引擎性能——比levelDB更牛叉!
热门文章
- Kinect 开发 —— 常见手势识别(下)
- tcp为什么要三次握手
- 关于IDEA编译器在初次使用thymeleaf 引入无效 , 导致th无法使用的原因
- 【2017 Multi-University Training Contest - Team 4】Time To Get Up
- BZOJ——T 1355: [Baltic2009]Radio Transmission
- https://github.com/ 英文库
- Python-根据成绩分析是否继续深造
- Java学习笔记九
- BZOJ1576: [Usaco2009 Jan]安全路经Travel(树链剖分)
- Linux登录状态