Laura L. Laura L. - 15 days ago 4x
C++ Question

Confused with C++ "simple" calculation with sign &

I am looking at a C++ source code where there is what looks to be a simply calculation. Yet with no knowledge in C++, I can't quite understand how it is really calculated (my goal being making the same calculation under Excel).

uint64_t fpo = (((ui>>32) << 24) | (ui & 0xffffff)) + 0x123e00;
PrintAndLog("ui result : %lld [0x%llX]", ui, ui);

In my case, ui is 0x0F007057B9
and the result is 0xF8295B9

If I take the windows Calculator, I do (in Hex mode)

(0x0F007057B9 AND 0xffffff) + 0x123e00

I am getting the same result (expect for the first 0xF)

I have read somewhere that AND returns 1 if both bits of same "weigh" are 1
So if I take ui AND 0xffffff converted to Binary :

0x0F007057B9 0000111100000000011100000101011110111001
0xffffff 111111111111111111111111

Which does make any change...

Am I completely going to wrong way?? Sorry for my poor english, I am from South Korea.
Thank you for helping me {^^;


For AND its

0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 0

So if you AND a number with 0xffffff, you basicly just keep the numbers at those positions. You fill in the missing ones with 0.

In your case:

0x0F007057B9 0000111100000000011100000101011110111001
0xffffff     0000000000000000111111111111111111111111

Im not sure, if that was your question tho :)