Byte values have the type Byte, which corresponds to an unsigned 8-bit
integer ranging from 0 to 255. It is generally recommended to use Int8
instead of Byte when performing math operations, however, Bytes are used in
API methods for Text and Path that deal with raw binary data, such as
Path.read_bytes() and Text.utf8(). Byte literals can be written using
the Byte() constructor: Byte(5).
The constructor also accepts text: Byte(text) evaluates to an optional
Byte? that is none unless the text is exactly one UTF-8 byte. When the
argument is a text literal, the conversion happens at compile time --
Byte("A")! compiles down to the C character literal 'A' with no runtime
check, and a literal that isn't exactly one byte (Byte("ab"), Byte("é"))
is a compile-time error rather than a guaranteed none.
Bytes support the bitwise operations x and y, x or y, x xor y, and not x (bitwise negation, flipping all eight bits), as well as bit shifting: x << y, x >> y, x <<< y, and x >>> y.
# Byte Values
Byte values have the type `Byte`, which corresponds to an unsigned 8-bit
integer ranging from 0 to 255. It is generally recommended to use `Int8`
instead of `Byte` when performing math operations, however, `Byte`s are used in
API methods for `Text` and `Path` that deal with raw binary data, such as
`Path.read_bytes()` and `Text.utf8()`. Byte literals can be written using
the `Byte()` constructor: `Byte(5)`.
The constructor also accepts text: `Byte(text)` evaluates to an optional
`Byte?` that is `none` unless the text is exactly one UTF-8 byte. When the
argument is a text literal, the conversion happens at compile time --
`Byte("A")!` compiles down to the C character literal `'A'` with no runtime
check, and a literal that isn't exactly one byte (`Byte("ab")`, `Byte("é")`)
is a compile-time error rather than a guaranteed `none`.
Bytes support the bitwise operations `x and y`, `x or y`, `x xor y`, and `not
x` (bitwise negation, flipping all eight bits), as well as bit shifting: `x <<
y`, `x >> y`, `x <<< y`, and `x >>> y`.
# API
[API documentation](../api/bytes.md)