您的位置:首页 > 其它

QRCode二维条码开发(计算格式信息)_2011.05.25

2011-05-25 17:09 162 查看
//函数功能:根据不同的纠错等级,计算15位的格式信息:BCH(15,5)
//参数说明:
//chErrLevel -- 纠错等级
//返回值:strFormatInformation -- 数据码字
CString CQRCodeDlg::CalculateFormatInformation(CString chErrLevel)
{
/*掩膜图形暂选101,因为一个图形一次只能选择一种掩膜方式*/
CString strFormatInformation;/*15位的格式信息串*/
CString strGeneratorInfo = "000010100110111";/*生成多项式信息串*/
CString strDataInfo;/*15位数据信息*/
char* cErrLevel;/*纠错等级*/
char buffer[15];
int nFlag1 = 16;/*非0位置标记,随便赋一个值*/
int nFlag2 = 16;/*非0位置标记,随便赋一个值*/
int nGeneratorInfo = 0;
int nDataInfo = 0;
cErrLevel = (LPSTR)(LPCSTR)chErrLevel;/*cstring类型数据转换为char型数据*/
switch(*cErrLevel)
{
case 'L':
strDataInfo = "011010000000000";/*数据信息位赋值,占据前5位*/
break;
case 'M':
strDataInfo = "001010000000000";
break;
case 'Q':
strDataInfo = "111010000000000";
break;
case 'H':
strDataInfo = "101010000000000";
break;
}
for(int i=0;i<15;i++)
{
if (strGeneratorInfo[i] == '1' && nFlag1 == 16)
nFlag1 = i;/*除数,根据差值进行移位*/
if (strDataInfo[i] == '1' && nFlag2 == 16)
nFlag2 = i;/*被除数*/
}
/*nFlag1>nFlag2,则需进行移位,然后进行位运算操作,同者为0,不同为1*/
nDataInfo = strtol(strDataInfo,NULL,2);
nGeneratorInfo = strtol(strGeneratorInfo,NULL,2)<<(nFlag1 - nFlag2);/*通过移位做除法*/
_itoa(nDataInfo^nGeneratorInfo,buffer,2);
strFormatInformation.Format("%015s",buffer);
strFormatInformation = strDataInfo.Left(5) + strFormatInformation.Right(10);
_itoa(strtol(strFormatInformation,NULL,2)^strtol("101010000010010",NULL,2),buffer,2);
strFormatInformation.Format("%015s",buffer);
return strFormatInformation;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐