@bytes
Convert a value to hex bytes, force UTF-8 encoding, or perform a bitwise operation.
On-chain (@bytes!): Bitwise operations run over the raw 32-byte words (shifts in bits, >> arithmetic on a signed value); with one argument it is the raw word cast.
Returns: bytes
Syntax
Section titled “Syntax”@bytes(a b? c?)Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
a | any | Value to convert or left operand |
[b] | string | Operator (& ` |
[c] | any | Right operand for bitwise ops |
Examples
Section titled “Examples”# Convert a number to bytesset $b @bytes(0xff)
# Bitwise ANDset $b @bytes(0xff00 "&" 0x0ff0)
# Left shiftset $b @bytes(0x01 "<<" 8)See Also
Section titled “See Also”- @bytes.not — bitwise NOT
- @bytes.concat — concatenate bytes
- @bytes.slice — extract a byte range
On-chain face (@bytes!)
Section titled “On-chain face (@bytes!)”Bitwise word operations computed on-chain (& | ^ << >>), or with a single argument the raw 32-byte word cast (e.g. bool as 0/1). Word-width semantics: operands are the raw 32-byte words; shifts are in bits, and >> on a signed value is the arithmetic shift (the sign fills in from the left).