I want to convert a hex string to a 32 bit signed integer in C++.
So, for example, I have the hex string \"fffefffe\". The binary representation of this is 111111
Andy Buchanan, as far as sticking to C++ goes, I liked yours, but I have a few mods:
template
struct HexTo {
ElemT value;
operator ElemT() const {return value;}
friend std::istream& operator>>(std::istream& in, HexTo& out) {
in >> std::hex >> out.value;
return in;
}
};
Used like
uint32_t value = boost::lexical_cast >("0x2a");
That way you don't need one impl per int type.