samedi 25 septembre 2021

Converting HEXA 64 bits numbers to int

I'm making a college job, a conversion between hexa numbers enclosed in a stringstream. I have a big hexa number (a private key), and I need to convert to int, to put in a map<int,int>. So when I run the code, the result of conversion is the same for all the two hexa values inserted, what is incorrect, it should be differente results after conversion. I think it's an int sizes stack problem, because when I insert short hexas, it works greatly. As shown below the hexa has 64 bits.

Any idea to get it working?

int main() {

unsigned int x;
std::stringstream ss; ss << std::hex <<0x3B29786B4F7E78255E9F965456A6D989A4EC37BC4477A934C52F39ECFD574444"; ss >> x;

std::cout << "Saida" << x << std::endl;
// output it as a signed type
std::cout << "Result 1: "<< static_cast<std::int64_t>(x) << std::endl;

ss << std::hex << "0x3C29786A4F7E78255E9A965456A6D989A4EC37BC4477A934C52F39ECFD573344";
ss >> x;
std::cout << "Saida 2 " << x << std::endl;
// output it as a signed type
std::cout << "Result 2: " << static_cast<std::int64_t>(x) << std::endl;

}

Aucun commentaire:

Enregistrer un commentaire