Primitive core::u16

u16
Expand description
16-bit unsigned integer

Implementations

fn min() -> Self

The smallest value that can be represented by this integer type.

Returns

  • [u16] - The smallest u16 value.

Examples

fn foo() {
    let val = u16::min();
    assert(val == 0u16);
}

fn max() -> Self

The largest value that can be represented by this integer type,
216 - 1.

Returns

  • [u16] - The largest u16 value.

Examples

fn foo() {
    let val = u16::max();
    assert(val == 65535u16);
}

fn bits() -> u64

The size of this integer type in bits.

Returns

  • [u32] - The number of bits for a u16.

Examples

fn foo() {
    let bits = u16::bits();
    assert(bits == 16);
}

fn zero() -> Self

Returns the zero value for the u16 type.

Returns

  • [u16] -> The zero value for the u16 type.

Examples

fn foo() {
    let zero_u16 = u16::zero();
    assert(zero_u16 == 0u16);
}

fn as_u32(self) -> u32

Extends a u16 to a u32.

Returns

  • [u32] - The converted u16 value.

Examples

fn foo() {
    let val = 10u16;
    let result = val.as_u32();
    assert(result == 10u32);
}

fn as_u64(self) -> u64

Extends a u16 to a u64.

Returns

  • [u64] - The converted u16 value.

Examples

fn foo() {
    let val = 10u16;
    let result = val.as_u64();
    assert(result == 10);
}

fn as_u256(self) -> u256

Extends a u16 to a u256.

Returns

  • [u256] - The converted u16 value.

Examples

fn foo() {
    let val = 2u16;
    let result = val.as_u256();
    assert(result == 0x0000000000000000000000000000000000000000000000000000000000000002u256);
}

Trait Implementations

fn add(self, other: Self) -> Self

fn subtract(self, other: Self) -> Self

fn multiply(self, other: Self) -> Self

fn divide(self, other: Self) -> Self

fn modulo(self, other: Self) -> Self

fn not(self) -> Self

fn eq(self, other: Self) -> bool

fn neq(self, other: Self) -> bool

Evaluates if two values of the same type are not equal.

Additional Information

This function is inherited when eq() is implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if the two values are not equal, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl Eq for MyStruct {
    fn eq(self, other: Self) -> bool {
         self.val == other.val
    }
}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 2 };
    let result = struct1 != struct2;
    assert(result);
}

fn gt(self, other: Self) -> bool

fn lt(self, other: Self) -> bool

fn binary_and(self, other: Self) -> Self

fn binary_or(self, other: Self) -> Self

fn binary_xor(self, other: Self) -> Self

fn ge(self, other: Self) -> bool

Evaluates if one value of the same type is greater or equal to than another.

Additional Information

This trait requires that the Ord and Eq traits are implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if self is greater than or equal to other, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl Eq for MyStruct {
    fn eq(self, other: Self) -> bool {
        self.val == other.val
    }
}

impl Ord for MyStruct {
    fn gt(self, other: Self) -> bool {
        self.val > other.val
    }
}

impl OrdEq for MyStruct {}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 10 };
    let result = struct1 >= struct2;
    assert(result);
}

fn le(self, other: Self) -> bool

Evaluates if one value of the same type is less or equal to than another.

Additional Information

This trait requires that the Ord and Eq traits are implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if self is less than or equal to other, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl Eq for MyStruct {
    fn eq(self, other: Self) -> bool {
        self.val == other.val
    }
}

impl Ord for MyStruct {
    fn lt(self, other: Self) -> bool {
        self.val < other.val
    }
}

impl OrdEq for MyStruct {}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 10 };
    let result = struct1 <= struct2;
    assert(result);
}

fn lsh(self, other: u64) -> Self

fn rsh(self, other: u64) -> Self

fn max(self, other: Self) -> Self

fn min(self, other: Self) -> Self

fn abi_encode(self, buffer: Buffer) -> Buffer

fn abi_decode(refmut buffer: BufferReader) -> u16