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

bin

bin(num: Scalar, /, *, prefix: StringSlice[StaticConstantOrigin] = StringSlice("0b")) -> String

Return the binary string representation an integral value.

print(bin(123))
print(bin(-123))
'0b1111011'
'-0b1111011'

Args:

Returns:

String: The binary string representation of num.

bin(b: Scalar[DType.bool], /, *, prefix: StringSlice[StaticConstantOrigin] = StringSlice("0b")) -> String

Returns the binary representation of a scalar bool.

Args:

Returns:

String: The binary string representation of b.

bin[T: Intable, //](num: T, /, *, prefix: StringSlice[StaticConstantOrigin] = StringSlice("0b")) -> String

Returns the binary representation of an indexer type.

Parameters:

  • T (Intable): The Intable type.

Args:

Returns:

String: The binary string representation of num.