Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Flip One Bit
00:00
5 left

Flip One Bit

EasyPython

Problem

Abbott device protocols such as FreeStyle Libre may encode sensor status and measurement flags in individual bits of a byte. Given an unsigned 8-bit value and a bit position, flip exactly that bit and return the resulting byte.

Bit positions are numbered from 0 through 7, where position 0 is the least significant bit. Flipping means changing 0 to 1 or 1 to 0, while leaving every other bit unchanged.

Formal Specification

Implement flip_bit(byte_value, bit_position).

  • Input: byte_value, an integer from 0 through 255, and bit_position, an integer from 0 through 7.
  • Output: An integer from 0 through 255 representing byte_value after the selected bit is toggled.
  • The input is valid, so no error handling is required.

Constraints

  • 0 <= byte_value <= 255
  • 0 <= bit_position <= 7
  • Exactly one bit is flipped
  • All unselected bits remain unchanged

Function Signature

def flip_bit(byte_value, bit_position):
Interviewer

Your question is Flip One Bit. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.