| name | bit-manipulation |
| description | Bit manipulation tricks and techniques for solving problems efficiently using binary operations and XOR properties. |
| sasmp_version | 1.3.0 |
| bonded_agent | 07-greedy-advanced |
| bond_type | PRIMARY_BOND |
| atomic_responsibility | bit_operation_execution |
| version | 2.0.0 |
| parameter_validation | {"strict":true,"rules":[{"name":"num","type":"integer","required":true},{"name":"bit_index","type":"integer","required":false}]} |
| retry_logic | {"max_attempts":3,"backoff_ms":[100,200,400],"retryable_errors":["overflow","timeout"]} |
| logging_hooks | {"on_start":true,"on_complete":true,"on_error":true,"log_format":"[BIT-SKILL] {timestamp} | {operation} | {status}"} |
| complexity_annotations | {"basic_ops":{"time":"O(1)","space":"O(1)"},"count_bits":{"time":"O(log n) or O(set bits)","space":"O(1)"},"subset_generation":{"time":"O(2^n)","space":"O(1) per subset"}} |
Bit Manipulation Skill
Atomic Responsibility: Execute bit-level operations for efficient problem solving.
Essential Bit Operations
def set_bit(num: int, i: int) -> int:
"""Set i-th bit to 1. Time: O(1)"""
return num | (1 << i)
def clear_bit(num: int, i: int) -> int:
"""Clear i-th bit to 0. Time: O(1)"""
return num & ~(1 << i)
def toggle_bit(num: int, i: int) -> int:
"""Toggle i-th bit. Time: O(1)"""
return num ^ (1 << i)
def is_bit_set(num: int, i: int) -> bool:
"""Check if i-th bit is set. Time: O(1)"""
return (num & (1 << i)) != 0
def is_power_of_two(n: int) -> bool:
"""Check if n is power of 2. Time: O(1)"""
return n > 0 and (n & (n - 1)) == 0
def () -> :
num & (-num)
() -> :
num & (num - )