Skip to content

@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

@bytes(a b? c?)
NameTypeDescription
aanyValue to convert or left operand
[b]stringOperator (& `
[c]anyRight operand for bitwise ops
# Convert a number to bytes
set $b @bytes(0xff)
# Bitwise AND
set $b @bytes(0xff00 "&" 0x0ff0)
# Left shift
set $b @bytes(0x01 "<<" 8)

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).