package octez-libs

  1. Overview
  2. Docs
A package that contains multiple base libraries used by the Octez suite

Install

Dune Dependency

Authors

Maintainers

Sources

tezos-octez-v20.1.tag.bz2
sha256=ddfb5076eeb0b32ac21c1eed44e8fc86a6743ef18ab23fff02d36e365bb73d61
sha512=d22a827df5146e0aa274df48bc2150b098177ff7e5eab52c6109e867eb0a1f0ec63e6bfbb0e3645a6c2112de3877c91a17df32ccbff301891ce4ba630c997a65

doc/octez-libs.stdlib/Tezos_stdlib/TzBytes/index.html

Module Tezos_stdlib.TzBytesSource

Sourceval logand : bytes -> bytes -> bytes

Bitwise AND on bytes.

If the arguments have different lengths, the prefix of the longer bytes is cut to have the same length as the shorter one before taking bitwise AND.

Example:

logand (Bytes.of_string "\xff\x0f") (Bytes.of_string "\xff") = Bytes.of_string "\x0f"

Sourceval logor : bytes -> bytes -> bytes

Bitwise OR on bytes.

If the arguments have different lengths, the shorter bytes is 0-padded on the left to have the same length before taking bitwise OR.

Example:

logor (Bytes.of_string "\xf0\x00") (Bytes.of_string "\x0f") = Bytes.of_string "\xf0\x0f"

Sourceval logxor : bytes -> bytes -> bytes

Bitwise XOR on bytes.

If the arguments have different lengths, the shorter bytes is 0-padded on the left to have the same length before taking bitwise XOR.

Example:

logxor (Bytes.of_string "\xf0\xff") (Bytes.of_string "\x0f") = Bytes.of_string "\xf0\xf0"

Sourceval lognot : bytes -> bytes

Bitwise NOT on bytes.

Example:

lognot (Bytes.of_string "\xff\xf0\xf0") = Bytes.of_string "\x00\x0f\x0f"

Sourceval shift_left : bytes -> int -> bytes

Logical shift left on bytes.

shift_left bs nbits shifts the byte contents left by nbits bits, using big-endian encoding. The vacated bits on the right are filled with 0s. The shifted bits are minimally 0-padded on the left in order to keep all the original bits: for example, 0x1234 LSL 1 is 0x002468, instead of 0x2468 (the left most bit is lost) or 0x00002468 (not minimal padding).

shift_left bs nbits raises Invalid_argument "shift_left" when nbits < 0.

Examples:

  • shift_left (Bytes.of_string "\x12\x34") 0 = Bytes.of_string "\x12\x34"
  • shift_left (Bytes.of_string "\xff\xff") 1 = Bytes.of_string "\x01\xff\xfe"
  • shift_left (Bytes.of_string "\x12\x34") 1 = Bytes.of_string "\x00\x24\x68" (not "\x24\x68")
  • shift_left (Bytes.of_string "\x00\x12\x34") 1 = Bytes.of_string "\x00\x00\x24\x68" (not "\x00\x24\x68")
  • shift_left (Bytes.of_string "\x00\x12\x34") 18 = Bytes.of_string "\x00\x48\xd0\x00\x00" (not "\x48\xd0\x00\x00")
  • shift_left Bytes.empty 1 = Bytes.of_string "\x00"
Sourceval shift_right : bytes -> int -> bytes

Logical shift right on bytes, using big-endian encoding.

shift_right bs nbits shifts the byte contents right by nbits bits, using big-endian encoding. The shifted bits are minimally 0-padded on the left to fit in bytes. For example, 0x123499 LSR 9 is 0xx091a, instead of 0x00091a (not minimal padding).

shift_right bs nbits raises Invalid_argument "shift_right" when nbits < 0.

Examples:

  • shift_right (Bytes.of_string "\x12\x34") 0 = Bytes.of_string "\x12\x34"
  • shift_right (Bytes.of_string "\x12\x34") 1 = Bytes.of_string "\x09\x1a"
  • shift_right (Bytes.of_string "\x12\x34") 8 = Bytes.of_string "\x12" (not "\x00\x12")
  • shift_right (Bytes.of_string "\x12\x34\x99") 9 = Bytes.of_string "\x09\xa"
  • shift_right (Bytes.of_string "\x12\x34") 18 = Bytes.empty
OCaml

Innovation. Community. Security.