GA-ASI
3.3 of 5
www.ga-asi.com Poway, CA 5000+ Employees

# GA-ASISoftware Engineer On CLAW Interview Question

I interviewed in San Diego, CA and was asked:
"Bitwise AND two numbers, and compare different bit positions for equality."

Part of a Software Engineer On CLAW Interview Review - one of 37 GA-ASI Interview Reviews

0
of 1
vote
Bitwise AND two 8 bit numbers

For each of the 8 bits, if both bits in the two numbers are one, the resulting bit is one, otherwise zero. Example: 0xD5 & 0x3E = 11010101 & 00111110 = 00010100 = 0x14

----------------

Write a function on the board that compares the 7th position in an 8 bit binary number to the 4th position in another 8 bit binary number. Return true if equal.

!(((0x40 & a) >> 6) ^ ((0x08 & b) >> 3))
(Note: first number represented by 'a', second number represented by 'b')

Explanation: Mask off the indicated bit in each number with a bitwise AND. Shift that bit to the first bit location. Perform a bitwise exclusive OR between the two bits (if the bits are the same, the answer will be zero). Perform a logical NOT to convert a zero to TRUE.
- Bob on Aug 9, 2012 Flag Response