0 out of 464 challenges solved
Write a Python function `left_rotate(n, d)` that rotates the bits of a 32-bit integer `n` to the left by `d` positions. The function should handle the wrap-around of bits correctly. #### Example Usage ```python [main.nopy] print(left_rotate(16, 2)) # Output: 64 print(left_rotate(10, 2)) # Output: 40 print(left_rotate(0b0001, 3)) # Output: 0b1000 ``` #### Constraints - Assume `n` is a 32-bit integer. - `d` is a non-negative integer. - The function should handle cases where `d` is greater than 32 by using modulo operation.
def left_rotate(n, d):
"""
Rotate the bits of a 32-bit integer n to the left by d positions.
Args:
n (int): The number to rotate.
d (int): The number of positions to rotate.
Returns:
int: The result of the left rotation.
"""
# Define the number of bits in the integer
INT_BITS = 32
# Placeholder for the solution
pass