Pergunta de entrevista da empresa Apple

Exchange the odd and even bits of an integer

Respostas da entrevista

Sigiloso

24 de out. de 2016

You have to get the odd and the even bits (using the & operator with 0xaaaaaaaa and 0x55555555). Then just shift the even to the right (>>1) and the odd to the left (<<1). Finally, result = newodd | neweven

Sigiloso

24 de out. de 2016

Uhmm... not signed and appeared as anonymous

Sigiloso

24 de out. de 2016

This is really a softball question but it's also pretty surprising that so many people is unable to nail it down. (( n & 0x55555555) > 1) & 0x55555555)

Sigiloso

24 de out. de 2016

Some formatting issue ((n & 0x55555555) > 1) & 0x55555555)