IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

Endian

struct Endian

A byte order: the order in which a multi-byte value's bytes are stored.

big stores the most significant byte first, which is also the network byte order, and little stores the least significant byte first. Endian.native() returns whichever of the two the compilation target uses, so data in that order needs no conversion.

Example:

var bytes = UInt16(8080).as_bytes[endian=.big]() # [0x1F, 0x90]

Implemented traits​

AnyType, Copyable, Deinitable, EnumLike, Equatable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable, Writable

comptime members​

big​

comptime big = Endian(_value=Int8(0))

Most significant byte first.

little​

comptime little = Endian(_value=Int8(1))

Least significant byte first.

Methods​

native​

static def native[target: CompilationTarget = CompilationTarget()]() -> Self

Returns the byte order of a compilation target.

Parameters:

Returns:

Self: Endian.big or Endian.little.