Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Bit Matching With Wildcards

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Bit Matching With Wildcards. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

A General Atomics MQ-9 telemetry packet contains two unsigned bytes, A and B. Their eight-bit representations follow these layouts:

  • A: 0101X110
  • B: 1Y011001

The digits 0 and 1 are arbitrary bit values supplied by the packet. Bit X is the fifth bit from the left in A, and bit Y is the second bit from the left in B. Return True when X and Y have the same value, otherwise return False.

Use bitwise operations rather than converting the bytes to strings. The function must work for every valid pair of bytes, regardless of the other bit values.

Formal Specification

Implement compare_telemetry_bits(A, B), where A and B are integers representing unsigned eight-bit values. Return a Boolean. Since bit positions are counted from the least significant bit at index 0, X is bit 3 of A, and Y is bit 6 of B.

Constraints

  • 0 <= A <= 255
  • 0 <= B <= 255
  • Both inputs represent exactly one unsigned byte
  • Only bit 3 of A and bit 6 of B affect the result

Function Signature

def compare_telemetry_bits(A, B):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output