struct UInt128

Defined in:

bytes_ext.cr

Constructors

Instance Method Summary

Constructor Detail

def self.from_be_bytes(bytes : Bytes) : UInt128 #

Create a UInt128 value from its representation as a byte array in big endian.

bytes = Bytes[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12]
UInt128.from_be_bytes(bytes)
# => 0x12345678901234567890123456789012_u128

[View source]
def self.from_bytes(bytes : Bytes, format : IO::ByteFormat = IO::ByteFormat::SystemEndian) : UInt128 #

Create a UInt128 value from its representation as a byte array.


[View source]
def self.from_le_bytes(bytes : Bytes) : UInt128 #

Create a UInt128 value from its representation as a byte array in little endian.

bytes = Bytes[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]
UInt128.from_le_bytes(bytes)
# => 0x12345678901234567890123456789012_u128

[View source]

Instance Method Detail

def to_be_bytes : Bytes #

Return the memory representation of this number as a byte array in big-endian (network) byte order.

bytes = "0x12345678901234567890123456789012_u128".to_be_bytes
# => Bytes[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12]

[View source]
def to_bytes(format : IO::ByteFormat = IO::ByteFormat::SystemEndian) : Bytes #

Return the memory representation of this number as a byte array using the specified format


[View source]
def to_le_bytes : Bytes #

Return the memory representation of this number as a byte array in little-endian byte order.

bytes = 0x12345678901234567890123456789012_u128.to_le_bytes
# => Bytes[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]

[View source]