Required Initializerswift 6.0.1Swift
init(_:)
Creates a new instance from the given integer.
init<T>(_ source: T) where T : BinaryInteger
Parameters
- source
An integer to convert.
source
must be representable in this type.
If the value passed as source
is not representable in this type, a runtime error may occur.
let x = -500 as Int
let y = Int32(x)
// y == -500
// -500 is not representable as a 'UInt32' instance
let z = UInt32(x)
// Error
Other requirements
View members
Hide members
This section is hidden by default because it contains too many (33) members.
Type members
associatedtype Words
A type that represents the words of a binary integer.
init<T>(T
) Creates an integer from the given floating-point value, rounding toward zero.
init<T>(clamping: T
) Creates a new instance with the representable value that’s closest to the given integer.
init?<T>(exactly: T
) Creates an integer from the given floating-point value, if it can be represented exactly.
init<T>(truncatingIfNeeded: T
) Creates a new instance from the bit pattern of the given instance by sign-extending or truncating to fit this type.
static var isSigned: Bool
A Boolean value indicating whether this type is a signed integer type.
static func % (lhs: Self, rhs: Self
) -> Self Returns the remainder of dividing the first value by the second.
static func %= (lhs: inout Self, rhs: Self
) Divides the first value by the second and stores the remainder in the left-hand-side variable.
static func & (lhs: Self, rhs: Self
) -> Self Returns the result of performing a bitwise AND operation on the two given values.
static func &= (lhs: inout Self, rhs: Self
) Stores the result of performing a bitwise AND operation on the two given values in the left-hand-side variable.
static func * (lhs: Self, rhs: Self
) -> Self Multiplies two values and produces their product.
static func *= (lhs: inout Self, rhs: Self
) Multiplies two values and stores the result in the left-hand-side variable.
static func + (lhs: Self, rhs: Self
) -> Self Adds two values and produces their sum.
static func += (lhs: inout Self, rhs: Self
) Adds two values and stores the result in the left-hand-side variable.
static func - (lhs: Self, rhs: Self
) -> Self Subtracts one value from another and produces their difference.
static func -= (lhs: inout Self, rhs: Self
) Subtracts the second value from the first and stores the difference in the left-hand-side variable.
static func / (lhs: Self, rhs: Self
) -> Self Returns the quotient of dividing the first value by the second.
static func /= (lhs: inout Self, rhs: Self
) Divides the first value by the second and stores the quotient in the left-hand-side variable.
static func << <RHS>(lhs: Self, rhs: RHS
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the left.
static func <<= <RHS>(lhs: inout Self, rhs: RHS
) Stores the result of shifting a value’s binary representation the specified number of digits to the left in the left-hand-side variable.
static func >> <RHS>(lhs: Self, rhs: RHS
) -> Self Returns the result of shifting a value’s binary representation the specified number of digits to the right.
static func >>= <RHS>(lhs: inout Self, rhs: RHS
) Stores the result of shifting a value’s binary representation the specified number of digits to the right in the left-hand-side variable.
static func ^ (lhs: Self, rhs: Self
) -> Self Returns the result of performing a bitwise XOR operation on the two given values.
static func ^= (lhs: inout Self, rhs: Self
) Stores the result of performing a bitwise XOR operation on the two given values in the left-hand-side variable.
static func | (lhs: Self, rhs: Self
) -> Self Returns the result of performing a bitwise OR operation on the two given values.
static func |= (lhs: inout Self, rhs: Self
) Stores the result of performing a bitwise OR operation on the two given values in the left-hand-side variable.
static func ~ (x: Self
) -> Self Returns the inverse of the bits set in the argument.
Instance members
var bitWidth: Int
The number of bits in the current binary representation of this value.
var trailingZeroBitCount: Int
The number of trailing zeros in this value’s binary representation.
var words: Self.Words
A collection containing the words of this value’s binary representation, in order from the least significant to most significant.
func isMultiple(of: Self
) -> Bool Returns
true
if this value is a multiple of the given value, andfalse
otherwise.func quotientAndRemainder(dividingBy: Self
) -> (quotient: Self, remainder: Self) Returns the quotient and remainder of this value divided by the given value.
func signum(
) -> Self Returns
-1
if this value is negative and1
if it’s positive; otherwise,0
.
Citizens in Swift
Default implementations
init<T>(T
) Creates a new instance from the given integer.
init<T>(T
) Creates a new instance from the given integer.
init?(String
) Creates a new integer value from the given string.
init<T>(T
) Creates an integer from the given floating-point value, rounding toward zero. Any fractional part of the value passed as
source
is removed.
Extension in BitCollections
Default implementations
init(BitArray
) Creates a new instance from the bits in the given bit array, if the corresponding integer value can be represented exactly. If the value is not representable exactly, then a runtime error will occur.