下面有個函數,用于將6個字節的字符數組‘轉換’到12字節。例如:

src[6] =
{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc }

dst[12] =
{ '1','2','3','4','5','6','7','8','9','a','b','c' }
因為目標是字符串風格,為了顯示需要,dst實際使用的是13字節長度數組,如下:
unsigned char dst[13];

makeId(dst, src);
函數如下,麻煩找下Bug。
void ISLUtil::makeId(unsigned char* id, const unsigned char* ptr)


{
int i = 0;
while(i < 6)

{
unsigned char t = *ptr >> 4;
if(t >= 0 && t <= 9)

{
*id = t + '0';
}
else if(t >= 0x0a && t <= 0x0f)

{
*id = t + 'a';
}
else

{
*id = 0;
}
t = (*ptr & 0x0F);
++ id;
if(t >= 0 && t <= 9)

{
*id = t + '0';
}
else if(t >= 0x0a && t <= 0x0f)

{
*id = t + 'a';
}
else

{
*id = 0;
}
++ ptr;
++ id;
++ i;
}
id[12] = '\0';
}
<----郁悶的分割線---->
Y的,白癡的錯誤搞了我兩天。。。。