Comparing two hexadecimal values ​​in C ++

I want to compare two hexadecimal (stored in long) below my code

long constant = 80040e14;
if(constant == 80040e14)
    cout<<"Success"<<endl;
else
    cout<<"Fail!!"<<endl;

In this control of code flow, the else part is always returned, can anyone suggest how to continue the comparison.

thank

Santosha K

+5
source share
6 answers

The prefix of your constants is "0x".

In your constant there is only "e", and the compiler will process the form numbers: NNNeEEE as scientific notation. Using the prefix '0x' tells the compiler that the following characters are in hexadecimal format.

80040e14 8004000000000000000, , 32- , 64- . 80040e14 , long float, , , - .

+13

0x ++

+3

0x e , . , , . - .

+2

==. , , , - , :

  • : , , . : 1 (), 2 (), 3 (),...

  • : 0x . : 0x01 (), 0x02 (), 0x03 (),...

  • Binary: 0b. : 0b01 (), 0xb10 (), 0b11 (). : , . .

:

long constant = 0x80040e14;
if(constant == 0x80040e14L)
    cout<<"Success"<<endl;
else
    cout<<"Fail!!"<<endl;
+1

hex?
0x80040e140x, , .

, float (e ), , .

0

80040e14 - . . 80040e14L - .

constant == 80040e14L

,

0.0 == 80040e14
0

All Articles