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
Whiteboard: Binary to String
00:00
5 left

Whiteboard: Binary to String

EasyPython

Problem

A Gentex embedded controller must encode signed sensor values into fixed-width binary fields before transmission. Implement a function that converts an integer to its binary representation without using Python's bin() or formatting helpers.

The result must use two's-complement representation and contain exactly bits characters. Positive values are left-padded with zeroes. Negative values are represented by adding 2^bits before extracting bits.

Formal Specification

Implement integer_to_binary(value, bits).

  • Input: value, an integer in the signed range -2^(bits-1) <= value < 2^(bits-1), and bits, an integer from 1 through 32.
  • Output: a string of exactly bits characters, each character either '0' or '1'.
  • Do not call bin(), format(), string conversion of the integer, or library-based base conversion.

Constraints

  • 1 <= bits <= 32
  • -2^(bits - 1) <= value < 2^(bits - 1)
  • The output contains exactly bits characters
  • Only '0' and '1' may appear in the output
  • Built-in binary conversion and formatting helpers are not allowed

Function Signature

def integer_to_binary(value, bits):
Interviewer

Your question is Whiteboard: Binary to String. 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.