IDP ready, I will upload my app to App Store tonight.
Ya!!!!!
2010年9月27日 星期一
2010年9月7日 星期二
[C++] Hex string convert to integer with stringstream
Sometimes we need to convert hex string to integer.
Usually we will use this alrorithm.
Tonight I found a question in CSDN, then I try to found a better solution.
In stackoverflow, I found this answer.
It is very nice.
Usually we will use this alrorithm.
char xtod(char c) {This is a conventional usage.
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 c=0; // not Hex digit
}
Tonight I found a question in CSDN, then I try to found a better solution.
In stackoverflow, I found this answer.
It is very nice.
#include <sstream>
#include <iostream>
int main() {
unsigned int x;
std::stringstream ss;
ss << std::hex << "FF";
ss >> x;
// output it as a signed type
std::cout << static_cast<int>(x) << std::endl;
}
訂閱:
文章 (Atom)