Skip to main content
Log in

Mojo function

bin

bin(num: SIMD[type, 1], /, *, prefix: StringSlice[0, MutableStaticLifetime] = "0b") -> String

Return the binary string representation an integral value.

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

Args:

  • num (SIMD[type, 1]): An integral scalar value.
  • prefix (StringSlice[0, MutableStaticLifetime]): The prefix of the formatted int.

Returns:

The binary string representation of num.

bin(b: SIMD[bool, 1], /, *, prefix: StringSlice[0, MutableStaticLifetime] = "0b") -> String

Returns the binary representation of a scalar bool.

Args:

  • b (SIMD[bool, 1]): A scalar bool value.
  • prefix (StringSlice[0, MutableStaticLifetime]): The prefix of the formatted int.

Returns:

The binary string representation of b.

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

Returns the binary representation of an indexer type.

Parameters:

  • T (Indexer): The Indexer type.

Args:

  • num (T): An indexer value.
  • prefix (StringSlice[0, MutableStaticLifetime]): The prefix of the formatted int.

Returns:

The binary string representation of num.

Was this page helpful?