Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Bit Manipulation: 4th LSB

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

Your question is Bit Manipulation: 4th LSB. 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

IBM watsonx monitoring processes configuration values supplied as decimal integers. Given a non-negative decimal integer n, return its fourth least significant bit in the number's binary representation. The least significant bit is bit position 0, so the requested bit is bit position 3.

Solve the problem using bit manipulation rather than converting the number to a binary string. The result must be either 0 or 1.

Formal Specification

Implement fourth_least_significant_bit(n), where n is a non-negative Python integer. Return an integer representing bit position 3 of n:

  • Return 1 if that bit is set.
  • Return 0 otherwise.

Leading zeroes in the binary representation do not affect the result.

Constraints

  • 0 <= n <= 10^18
  • n is a non-negative integer
  • The result must be either 0 or 1

Function Signature

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