#uint16

    The moonbitlang/core/uint16 package provides functionality for working with 16-bit unsigned integers. This package includes constants, operators, and conversions for UInt16 values.

    #Constants

    The package defines the minimum and maximum values for UInt16:

    ///|
    test "UInt16 constants" {
    // Minimum value of UInt16
    inspect(@uint16.MIN_VALUE, content="0")

    // Maximum value of UInt16
    inspect(@uint16.MAX_VALUE, content="65535")
    }

    #Arithmetic Operations

    UInt16 supports standard arithmetic operations:

    ///|
    test "UInt16 arithmetic" {
    let a : UInt16 = 100
    let b : UInt16 = 50

    // Addition
    inspect(a + b, content="150")

    // Subtraction
    inspect(a - b, content="50")

    // Multiplication
    inspect(a * b, content="5000")

    // Division
    inspect(a / b, content="2")

    // Overflow behavior
    inspect(@uint16.MAX_VALUE + 1, content="0") // Wraps around to 0
    inspect(@uint16.MIN_VALUE - 1, content="65535") // Underflow wraps to maximum value
    }

    #Bitwise Operations

    UInt16 supports various bitwise operations:

    ///|
    test "UInt16 bitwise operations" {
    let a : UInt16 = 0b1010
    let b : UInt16 = 0b1100

    // Bitwise AND
    inspect(a & b, content="8")

    // Bitwise OR
    inspect(a | b, content="14")

    // Bitwise XOR
    inspect(a ^ b, content="6")

    // Left shift
    inspect(a << 1, content="20")
    inspect(a << 2, content="40")

    // Right shift
    inspect(a >> 1, content="5")
    inspect(b >> 2, content="3")
    }

    #Comparison and Equality

    UInt16 supports comparison and equality operations:

    ///|
    test "UInt16 comparison and equality" {
    let a : UInt16 = 100
    let b : UInt16 = 50
    let c : UInt16 = 100

    // Equality
    inspect(a == c, content="true")
    inspect(a != b, content="true")

    // Comparison
    inspect(a > b, content="true")
    inspect(b < a, content="true")
    inspect(a >= c, content="true")
    inspect(c <= a, content="true")
    }

    #Default Value and Hashing

    UInt16 implements the Default trait:

    ///|
    test "UInt16 default value" {
    // Default value is 0
    let a : UInt16 = 0
    inspect(a, content="0")

    // Hash support is available via hash()
    let value : UInt16 = 42
    // This may be random per process
    let _ = hash(value)
    }

    #Type Conversions

    UInt16 works with various conversions to and from other types:

    ///|
    test "UInt16 conversions" {
    // From Int to UInt16
    inspect((42).to_uint16(), content="42")

    // From UInt16 to Int
    let value : UInt16 = 100
    inspect(value.to_int(), content="100")

    // Overflow handling in conversions
    inspect((-1).to_uint16(), content="65535") // Negative numbers wrap around
    inspect((65536).to_uint16(), content="0") // Values too large wrap around
    inspect((65537).to_uint16(), content="1") // 65536 + 1 = 1 (modulo 65536)

    // From Byte to UInt16
    inspect(b'A'.to_uint16(), content="65")
    inspect(b'\xFF'.to_uint16(), content="255")
    }

    UInt16

    UInt16::reinterpret_as_int16

    #deprecated("Use `Int16::reinterpret_from_uint16` instead")
    fn UInt16::reinterpret_as_int16(self : UInt16) -> Int16

    Function reinterpret_as_int16.

    MAX_VALUE

    let MAX_VALUE : UInt16

    Max value constant for this type.

    MIN_VALUE

    let MIN_VALUE : UInt16

    Min value constant for this type.

    max_value

    #deprecated("Use `MAX_VALUE` instead")
    let max_value : UInt16

    Max value constant for this type.

    min_value

    #deprecated("Use `MIN_VALUE` instead")
    let min_value : UInt16

    Min value constant for this type.

    Source Files