UInt128 - OpenDive/AptosKit GitHub Wiki
UInt128
A 128-bit unsigned integer value type. Storage is based upon a tuple of 2, 64-bit, unsigned integers.
public struct UInt128
Inheritance
BinaryInteger, Codable, Comparable, CustomDebugStringConvertible, CustomStringConvertible, Equatable, ExpressibleByIntegerLiteral, FixedWidthInteger, Hashable, Numeric
Initializers
init(upperBits:lowerBits:)
Designated initializer for the UInt128 type.
public init(upperBits: UInt64, lowerBits: UInt64)
init()
public init()
init?(_:)
Initialize a UInt128 value from a string.
Returns nil if input cannot be converted to a UInt128 value.
public init?(_ source: String)
Parameters
- source: the string that will be converted into a UInt128 value. Defaults to being analyzed as a base10 number, but can be prefixed with
0bfor base2,0ofor base8 or0xfor base16.
init(_truncatingBits:)
Creates a UInt128 from a given value, with the input's value truncated to a size no larger than what UInt128 can handle. Since the input is constrained to an UInt, no truncation needs to occur, as a UInt is currently 64 bits at the maximum.
public init(_truncatingBits bits: UInt)
init(bigEndian:)
Creates an integer from its big-endian representation, changing the byte order if necessary.
public init(bigEndian value: UInt128)
init(littleEndian:)
Creates an integer from its little-endian representation, changing the byte order if necessary.
public init(littleEndian value: UInt128)
init?(exactly:)
public init?<T : BinaryFloatingPoint>(exactly source: T)
init(_:)
public init<T : BinaryFloatingPoint>(_ source: T)
init(integerLiteral:)
public init(integerLiteral value: IntegerLiteralType)
init(from:)
public init(from decoder: Decoder) throws
init(stringLiteral:)
The required initializer of ExpressibleByStringLiteral.
@available(swift, deprecated: 5.0, message: "The ExpressibleByStringLiteral conformance has been removed. Use failable initializer instead.", renamed: "init(_:)")
public init(stringLiteral value: StringLiteralType)
Note that the ExpressibleByStringLiteral conformance has been removed because it
does not handle failures gracefully and it always shadows the failable initializer in Swift 5.
Properties
significantBits
Counts up the significant bits in stored data.
public var significantBits: UInt128
nonzeroBitCount
public var nonzeroBitCount: Int
leadingZeroBitCount
public var leadingZeroBitCount: Int
bigEndian
Returns the big-endian representation of the integer, changing the byte order if necessary.
public var bigEndian: UInt128
littleEndian
Returns the little-endian representation of the integer, changing the byte order if necessary.
public var littleEndian: UInt128
byteSwapped
Returns the current integer with the byte order swapped.
public var byteSwapped: UInt128
bitWidth
public static var bitWidth : Int
words
public var words: [UInt]
trailingZeroBitCount
public var trailingZeroBitCount: Int
description
public var description: String
debugDescription
public var debugDescription: String
Methods
addingReportingOverflow(_:)
public func addingReportingOverflow(_ rhs: UInt128) -> (partialValue: UInt128, overflow: Bool)
subtractingReportingOverflow(_:)
public func subtractingReportingOverflow(_ rhs: UInt128) -> (partialValue: UInt128, overflow: Bool)
multipliedReportingOverflow(by:)
public func multipliedReportingOverflow(by rhs: UInt128) -> (partialValue: UInt128, overflow: Bool)
multipliedFullWidth(by:)
public func multipliedFullWidth(by other: UInt128) -> (high: UInt128, low: UInt128.Magnitude)
dividedReportingOverflow(by:)
public func dividedReportingOverflow(by rhs: UInt128) -> (partialValue: UInt128, overflow: Bool)
dividingFullWidth(_:)
public func dividingFullWidth(_ dividend: (high: UInt128, low: UInt128)) -> (quotient: UInt128, remainder: UInt128)
remainderReportingOverflow(dividingBy:)
public func remainderReportingOverflow(dividingBy rhs: UInt128) -> (partialValue: UInt128, overflow: Bool)
quotientAndRemainder(dividingBy:)
public func quotientAndRemainder(dividingBy rhs: UInt128) -> (quotient: UInt128, remainder: UInt128)
hash(into:)
public func hash(into hasher: inout Hasher)
encode(to:)
public func encode(to encoder: Encoder) throws
fromUnparsedString(_:)
Initialize a UInt128 value from a string.
@available(swift, deprecated: 3.2, renamed: "init(_:)")
public static func fromUnparsedString(_ source: String) throws -> UInt128
Parameters
- source: the string that will be converted into a UInt128 value. Defaults to being analyzed as a base10 number, but can be prefixed with
0bfor base2,0ofor base8 or0xfor base16.
Operators
/
public static func /(lhs: UInt128, rhs: UInt128) -> UInt128
/=
public static func /=(lhs: inout UInt128, rhs: UInt128)
%
public static func %(lhs: UInt128, rhs: UInt128) -> UInt128
%=
public static func %=(lhs: inout UInt128, rhs: UInt128)
&=
Performs a bitwise AND operation on 2 UInt128 data types.
public static func &=(lhs: inout UInt128, rhs: UInt128)
|=
Performs a bitwise OR operation on 2 UInt128 data types.
public static func |=(lhs: inout UInt128, rhs: UInt128)
^=
Performs a bitwise XOR operation on 2 UInt128 data types.
public static func ^=(lhs: inout UInt128, rhs: UInt128)
&>>=
Perform a masked right SHIFT operation self.
public static func &>>=(lhs: inout UInt128, rhs: UInt128)
The masking operation will mask rhs against the highest
shift value that will not cause an overflowing shift before
performing the shift. IE: rhs = 128 will become rhs = 0
and rhs = 129 will become rhs = 1.
&<<=
Perform a masked left SHIFT operation on self.
public static func &<<=(lhs: inout UInt128, rhs: UInt128)
The masking operation will mask rhs against the highest
shift value that will not cause an overflowing shift before
performing the shift. IE: rhs = 128 will become rhs = 0
and rhs = 129 will become rhs = 1.
+
public static func +(lhs: UInt128, rhs: UInt128) -> UInt128
+=
public static func +=(lhs: inout UInt128, rhs: UInt128)
-
public static func -(lhs: UInt128, rhs: UInt128) -> UInt128
-=
public static func -=(lhs: inout UInt128, rhs: UInt128)
*
public static func *(lhs: UInt128, rhs: UInt128) -> UInt128
*=
public static func *=(lhs: inout UInt128, rhs: UInt128)
==
Checks if the lhs is equal to the rhs.
public static func ==(lhs: UInt128, rhs: UInt128) -> Bool
<
public static func <(lhs: UInt128, rhs: UInt128) -> Bool