lizhendong
級別: 家園常客
|
C語言大俠們,如何詳細解讀這兩個函數??? 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; } |
---|---|
|
liuliangdt
liuliangdt
級別: 家園常客
|
//b24e是一個返回char類型指針的函數,函數帶3個參數。一個signed char類型指針,一個unsigned char類型指針,一個堆棧塊數量的參數 char *b24e(char *buf, unsigned char *byst, size_t sizeOfBytes) { int i = 0; //指針p指向形參(*byst) unsigned char *p = byst; //第一次循環(i = p - byst) = 0強制轉換成(size_t)類型跟參數sizeOfBtes比較。結果大概率是真 while ((size_t)(i = (p-byst)) < sizeOfBytes) { //sel是數組。數據(*p)右移4位作為sel數組的標號。(sel[((*p) >> 4)]是作32位數據處理,并且是在做類似壓棧操作。buf[2 * i]是char類型數組,搞不懂為什么這樣做?) buf[2*i] = sel[((*p) >> 4)]; //((*p) & 0x0f)是上面右移了的4位,最小是0,最大是15。sel[8~23]中的一個字節數據賦值給buf[(2*i)+1] buf[(2*i)+1] = sel[23 - ((*p) & 0x0f)]; //指針加一 p++; } //數組byst處理完后在buf后面加0,數組bug[]現在存的是字符串數據 buf[(2*i)+1] = '\0'; //返回指針buf return buf; } 太難了,我也不知道什么意思,歡迎大神指正錯誤。 |
---|---|
|