上传者: xiaoyu20050805
|
上传时间: 2021-09-02 18:37:24
|
文件大小: 4.47MB
|
文件类型: RAR
最近要写个MEID第15位校验位的程序,发现当全是数字的时候,沿用16进制的算法不对,最后发现其是用十进制的。贴出代码参考。
void CCM810TestDlg::Meid()
{
int i_value=0,j=0,k=0,l=0,i_temp=0;
int i_array[10];
int i_rcr=0;
int MobIdValue=0;
CString strTemp;
bool bDec=true;
memset(i_array, 0, sizeof(i_array));
//char MeMeidStr[15] ={'2','3','5','4','5','6','7','8','9','1','2','3','6','a'};1234567891236
//char MeMeidStr[15] ={'1','2','3','4','5','6','7','8','9','1','2','3','6','A'};74185296321456
//char MeMeidStr[15] ={'7','4','1','8','5','2','9','6','3','2','1','4','5','6'};
char MeMeidStr[15] ={'1','0','0','0','0','0','0','0','0','0','1','1','1','7'};
AddInfo("\r\ndd");
for(l=0;l<14;l++)
{
switch (MeMeidStr[l])
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
MobIdValue = (MeMeidStr[l]-'0');
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
bDec = false;
MobIdValue = (MeMeidStr[l]-'a')+10;
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
bDec = false;
MobIdValue = (MeMeidStr[l]-'A')+10;
break;
default:
AddInfo("\r\nerror");
return;
}
/* if(l==0)
{
i_value += MobIdValue;
}
else if(l==1)
{
i_value += MobIdValue;
} */
if((l+1)%2)
{
i_value += MobIdValue; //ÆæÊý
}
else
{
i_array[j] = 2* MobIdValue;
j++;
}
}
for(k=0; k<7;k++)
{
if(bDec)