Pergunta de entrevista da empresa General Atomics

Given bytes "A" and "B" whose bit representations can be written as "0101X110" and "1Y011001" write a function to take in bytes "A" and "B" and return true if bits "X" and "Y" are the same or return false if they are not the same. Assume the 1s and 0s in "A" and "B" are arbitrary.

Respostas da entrevista

Sigiloso

20 de nov. de 2017

Two ways (assuming byte types): if ((A << 4 ) ^ (B << 1)) return false; else return true; OR if ((!(A& 0b00001000) && !(B& 0b01000000) ) || (!!(A& 0b00001000) && !!(B& 0b01000000) )) return true; else return false;

Sigiloso

20 de nov. de 2017

Two ways (assuming byte types): MINOR SIMPLIFICATION TO SECOND OPTION if ((A << 4 ) ^ (B << 1)) return false; else return true; OR if (!(A& 0b00001000) == !(B& 0b01000000) ) return true; else return false;