Skip to content

Support bitwise operations for bytesX types #4305

@pcaversaccio

Description

@pcaversaccio

Summary

Add support for the bitwise unary operator ~, the bitwise binary operators &, |, and ^, and the shift operators >> and <<. An example use case can be packing:

@internal
def _pack_1_1(left: bytes1, right: bytes1) -> bytes2:
    left = left & convert((max_value(uint256) << 248), bytes1)
    right = right & convert((max_value(uint256) << 248), bytes1)
    return left | (right >> 8)

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions