Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XOR higher 32 bits with lower 32 bits in a 64 bit number

Tags:

c++

algorithm

In a 64 bit number How to XOR Higher order 32 bits with lower order 32 bits. Thank you

like image 532
Vikas Kulkarni Avatar asked Dec 27 '22 18:12

Vikas Kulkarni


2 Answers

(v & 0xffffffff) ^ ((v >> 32) & 0xffffffff)
like image 58
Ignacio Vazquez-Abrams Avatar answered Jan 15 '23 12:01

Ignacio Vazquez-Abrams


Just for kicks, here's another solution. The one given already is probably the way to go.

uint32_t* number32;
uint64_t number64 = 0xffff1111ffffffff;
uint32_t xorValue;

number32 = (uint32_t*)&number64;
xorValue = number32[0]^number32[1];
like image 45
Kyle Avatar answered Jan 15 '23 11:01

Kyle