I want to compare two hexadecimal(stored in long) below is my code
long constant = 80040e14;
if(constant == 80040e14)
cout<<"Success"<<endl;
else
cout<<"Fail!!"<<endl;
In this code flow control always returns to else part, can anyone please suggest how to proceed with the comparison.
Thanks
Santhosha K
Prefix your constants with '0x'.
Your constant only has 'e' in it and the compiler will treat numbers of the form: NNNeEEE as scientific notation. Using the '0x' prefix tells the compiler that the following characters are in hexadecimal notation.
In your code, 80040e14 is 8004000000000000000 which is way too big to fit into 32bit value but can fit into a 64bit value. But, 80040e14 is a floating point number so the comparison will convert the long to a float to make it the same type as the constant and so the two values will be different due to the complexities of floating point code.
You need to put 0x in front of your hexadecimal numbers in C++
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With