小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C++ char轉(zhuǎn)十六進(jìn)制

 herowuking 2015-06-05
復(fù)制代碼
int hexCharToInt(char c)  
{   
        if (c >= '0' && c <= '9') return (c - '0');  
        if (c >= 'A' && c <= 'F') return (c - 'A' + 10);  
        if (c >= 'a' && c <= 'f') return (c - 'a' + 10);  
        return 0;  
}  
  
char* hexstringToBytes(string s)  
{           
        int sz = s.length();  
        char *ret = new char[sz/2];  
        for (int i=0 ; i <sz ; i+=2) {  
            ret[i/2] = (char) ((hexCharToInt(s.at(i)) << 4)  
                                | hexCharToInt(s.at(i+1)));  
        }  
        return ret;  
}  
  
string bytestohexstring(char* bytes,int bytelength)  
{  
  string str("");  
  string str2("0123456789abcdef");   
   for (int i=0;i<bytelength;i++) {  
     int b;  
     b = 0x0f&(bytes[i]>>4);  
     char s1 = str2.at(b);  
     str.append(1,str2.at(b));            
     b = 0x0f & bytes[i];  
     str.append(1,str2.at(b));  
     char s2 = str2.at(b);  
   }  
   return str;  
}  
  
int main()  
{  
        char s[3] ={'a','b','c'};  

        std::string result;

        result = bytestohexstring(s,strlen(s));  

        for(int i=0;i<3;i++)
        {
            printf("%02x", s[i]&0xFF);
        }

        printf("\n%s\n",result.data());

        system("pause"); }
復(fù)制代碼

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多