Count Set Bits
Implement a function that returns the number of set bits (1s) in the binary representation of a non-negative integer.
Check Power of Two Bits
Implement is_power_of_two(n) that returns True if n is a power of two and False otherwise.
Single Number XOR
Given a non-empty list of integers where every element appears twice except one, return the single number using XOR.
Gray Code Encode
Implement a function that converts a non-negative integer to its Gray code representation using bitwise XOR and shift.
Gray Code Decode
Implement gray_decode(n) that converts an n-bit Gray code integer back to its standard binary value using XOR accumulation.
Find Rightmost Set Bit
Implement a function that returns the 1-indexed position of the rightmost set bit of a positive integer, or 0 if none.
Isolate Rightmost Set Bit
Given an integer, return a number with only its rightmost set bit set.
Rotate Bits Left
Implement a function that rotates the bits of an integer to the left by a specified number of positions.
Add without plus
Implement a function that adds two integers using only bitwise operations, no arithmetic plus or minus.
Set kth Bit
Implement a function that sets the kth bit (0-indexed) of a non-negative integer to 1 and returns the result.
Clear kth Bit
Implement a function that clears the k-th bit of a non-negative integer (turns it to 0) using bitwise operations.
Sparse Number Check
Check if a non-negative integer is sparse, meaning its binary representation contains no adjacent 1 bits.
Brian Kernighan count
Implement a function that counts set bits using Brian Kernighan's efficient algorithm.
Showing 13 challenges · easy · Bit Manipulation
Bit Manipulation — Python coding challenges
What you will find here
This page lists bit manipulation challenges — real Python problems you solve in the browser IDE with instant test feedback. Each challenge includes a clear brief, starter code, and automated checks.
Challenges vs tutorials and quizzes
Challenges test what you can build under constraints. For guided teaching, use our Python tutorials. For quick checks, try quizzes or copy snippets from code samples.