zoukankan      html  css  js  c++  java
  • 从字符串中提取BCD码,转换为UINT数据并返回

    C++ code:

    #include <iostream>
    #include <iomanip>
    #include <windows.h>
    
    using namespace std;
    
    /*
    	功能:将BCD码转换为UINT数据
    	@p:			存储BCD码的字符串数组
    	@len:		表示一个BCD码的字符长度
    	@retValue:	保存一个BCD码的返回值
    */
    char * BCDtoUINT(char *p, int len, UINT & retValue)
    {
    	retValue = 0;
    	for(int i = 0; i < len; i++, p++)
    	{
    		retValue = retValue * 100 + (*p >> 4) * 10 + (*p & 0x0F);
    	}
    	return p;
    }
    
    void main()
    {
    	char a[10] = {0x00, 0x21, 0x01, 0x11, 0x26, 0x00, 0x09, 0x00, 0x00, 0x01};
    	char * p = a;
    
    	unsigned int seq[3];
    	p = BCDtoUINT(p, 3, seq[0]);
    	p = BCDtoUINT(p, 4, seq[1]);
    	p = BCDtoUINT(p, 3, seq[2]);
    
    	for(int i = 0; i < 3; i++)
    	{
    		cout<<seq[i]<<' ';
    	}
    	cout<<endl;
    }
    
    /*
    	运行结果:
    	2101 11260009 1
    */
    
  • 相关阅读:
    CDQ分治
    [noip模拟赛2017.7.15]
    [noip模拟赛2017.7.11]
    [noip模拟赛2017.7.10]
    [noip模拟赛2017.7.7]
    [noip模拟赛2017.7.6]
    [noip模拟赛2017.7.4]
    回文检测
    mapreduce引用第三方jar
    Spark安装和配置
  • 原文地址:https://www.cnblogs.com/joeblackzqq/p/1890031.html
Copyright © 2011-2022 走看看