lizhendong
級(jí)別: 家園常客
精華主題: 0
發(fā)帖數(shù)量: 608 個(gè)
工控威望: 800 點(diǎn)
下載積分: 1992 分
在線(xiàn)時(shí)間: 851(小時(shí))
注冊(cè)時(shí)間: 2016-10-12
最后登錄: 2024-12-22
查看lizhendong的 主題 / 回貼
樓主  發(fā)表于: 2022-07-10 22:57
這個(gè)函數(shù)原理和調(diào)用????C的高手看看!!


static const char sel[] = {
'B','C','D','F','G',
'H','J','K','M','P',
'Q','R','T','V','W',
'X','Y','2','3','4',
'6','7','8','9', '\0'};

char *b24e(char *buf, unsigned char *byst, size_t sizeOfBytes)
{
int i = 0;
unsigned char *p = byst;
while ((size_t)(i = (p-byst)) < sizeOfBytes) {
  buf[2*i] = sel[((*p) >> 4)];
  buf[(2*i)+1] = sel[23 - ((*p) & 0x0f)];
  p++;
}
buf[(2*i)+1] = '\0';
return buf;
}

unsigned char *b24d(unsigned char *buf, char *str, size_t countOfChars)
{
size_t i;
char *p = str;
char *loc[2];
unsigned char n[2];
if (countOfChars % 2)
  return NULL;
for (i = 0; i < (countOfChars>>1); i++) {

  loc[0] = strchr( sel, str[2*i] );
  loc[1] = strchr( sel, str[ ( 2*i ) + 1 ] );
  if (loc[0] == NULL || loc[1] == NULL)
   return NULL;
  n[0] = (unsigned char)( loc[0] - sel );
  n[1] = 23 - (unsigned char)( loc[1] - sel );
  buf = (unsigned char)((n[0] << 4) | n[1]);
}
return buf;
}
ccc189
級(jí)別: 略有小成
精華主題: 0
發(fā)帖數(shù)量: 56 個(gè)
工控威望: 223 點(diǎn)
下載積分: 5048 分
在線(xiàn)時(shí)間: 2400(小時(shí))
注冊(cè)時(shí)間: 2022-07-04
最后登錄: 2024-11-25
查看ccc189的 主題 / 回貼
1樓  發(fā)表于: 2022-07-12 17:20