Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
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

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.