FunctionRacerProblemsRace

Read One Bit

BeginnerBitsPython, JavaScript, TypeScript, Java, C++

Written in binary, a number is a row of bits. Position 0 is the lowest bit, the one worth 1; position 1 is worth 2, position 2 is worth 4, and so on.

Return the bit of n at position k: 1 or 0. A position beyond the highest 1 of n holds a 0.

Example 1

n 13
k 2
returns 1

13 is 1101 in binary. Position 2, the third bit from the right, is 1.

Example 2

n 13
k 1
returns 0

13 is 1101. Position 1 is 0.

Example 3

n 5
k 10
returns 0

Position 10 lies far above the highest bit of 5.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems