[新手问题]关于字符串转成二进制的
现在我用TEdit接受了一个字符串,问题是这里面有字母有汉字还可能有标点,而我现在想把它转成二维二进制[][8] 存在数组里。
每个字或标点转成8位二进制。这个该怎么弄啊。在bulider里有这样的方法 直接将string转为二进制的么?
[解决办法]
int len = strlen( edt1->Text.t_str());char *kkk = new char[len];strcpy(kkk,edt1->Text.t_str());
[解决办法]
string BinaryData[16] = { "0000","0001","0010","0011", "0100","0101","0110","0111", "1000","1001","1010","1011", "1100","1101","1110","1111"};string HexToBinary(const string HexData){ string Bin(""); for( int i=0; i<HexData.size(); i++ ) { int posVal = (int)HexData.at(i); if (posVal >= '0' && posVal <= '9') posVal -= '0'; else if (posVal >= 'A' && posVal <= 'Z') posVal = (posVal - 'A') + 10; Bin += BinaryData[posVal]; } return Bin;}