Nat16

The convention is to name the module alias after the file name it is defined in:

import Nat16 "mo:base/Nat16";

On this page

Constants

Value minimumValue
Value maximumValue

Conversion

Function toNat
Function toText
Function fromNat
Function fromIntWrap

Comparison

Function min
Function max
Function equal
Function notEqual
Function less
Function lessOrEqual
Function greater
Function greaterOrEqual
Function compare

Numerical Operations

Function add
Function sub
Function mul
Function div
Function rem
Function pow

Bitwise Operators

Function bitnot
Function bitand
Function bitor
Function bitxor
Function bitshiftLeft
Function bitshiftRight
Function bitrotLeft
Function bitrotRight
Function bittest
Function bitset
Function bitclear
Function bitflip
Function bitcountNonZero
Function bitcountLeadingZero
Function bitcountTrailingZero

Wrapping Operations

Function addWrap
Function subWrap
Function mulWrap
Function powWrap

minimumValue

let minimumValue : Nat16 = 0;

maximumValue

let maximumValue : Nat16 = 65_535;

Nat16.toNat

 func toNat(i : Nat16) : Nat

The function toNat takes one Nat16 value and returns a Nat value.

import Nat16 "mo:base/Nat16";

let a : Nat16 = 65535;

Nat16.toNat(a);

Nat16.toText

 func toText(i : Nat16) : Text

The function toText takes one Nat16 value and returns a Text value.

import Nat16 "mo:base/Nat16";

let b : Nat16 = 65535;

Nat16.toText(b);

Nat16.fromNat

 func fromNat(i : Nat) : Nat16

The function fromNat takes one Nat value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let number : Nat = 65535;

Nat16.fromNat(number);

Nat16.fromIntWrap

 func fromIntWrap(i : Int) : Nat

The function fromIntWrap takes one Int value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let integer : Int = 65537;

Nat16.fromIntWrap(integer);

Nat16.min

func min(x : Nat16, y : Nat16) : Nat16

The function min takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 200;
let y : Nat16 = 100;

Nat16.min(x, y);

Nat16.max

func max(x : Nat16, y : Nat16) : Nat16

The function max takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 200;
let y : Nat16 = 100;

Nat16.max(x, y);

Nat16.equal

func equal(x : Nat16, y : Nat16) : Bool

The function equal takes two Nat16 value and returns a Bool value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 10;
let y : Nat16 = 10;

Nat16.equal(x, y);

Nat16.notEqual

func notEqual(x : Nat16, y : Nat16) : Bool

The function notEqual takes two Nat16 value and returns a Bool value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 100;
let y : Nat16 = 100;

Nat16.notEqual(x, y);

Nat16.less

func less(x : Nat16, y : Nat16) : Bool

The function less takes two Nat16 value and returns a Bool value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 255;
let y : Nat16 = 256;

Nat16.less(x, y);

Nat16.lessOrEqual

func lessOrEqual(x : Nat16, y : Nat16) : Bool

The function lessOrEqual takes two Nat16 value and returns a Bool value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 255;
let y : Nat16 = 256;

Nat16.lessOrEqual(x, y);

Nat16.greater

func greater(x : Nat16, y : Nat16) : Bool

The function greater takes two Nat16 value and returns a Bool value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 150;
let y : Nat16 = 100;

Nat16.greater(x, y);

Nat16.greaterOrEqual

func greaterOrEqual(x : Nat16, y : Nat16) : Bool

The function greaterOrEqual takes two Nat16 value and returns a Bool value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 150;
let y : Nat16 = 100;

Nat16.greaterOrEqual(x, y);

Nat16.compare

func compare(x : Nat16, y : Nat16) : Bool

The function compare takes two Nat16 value and returns an Order variant value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 1001;
let y : Nat16 = 1000;

Nat16.compare(x, y);

Nat16.add

func add(x : Nat16, y : Nat16) : Nat16

The function add takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 400;
let y : Nat16 = 100;

Nat16.add(x, y);

Nat16.sub

func sub(x : Nat16, y : Nat16) : Nat16

The function sub takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 400;
let y : Nat16 = 200;

Nat16.sub(x, y);

Nat16.mul

func mul(x : Nat16, y : Nat16) : Nat16

The function mul takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 20;
let y : Nat16 = 50;

Nat16.mul(x, y);

Nat16.div

func div(x : Nat16, y : Nat16) : Nat16

The function div takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 5000;
let y : Nat16 = 50;

Nat16.div(x, y);

Nat16.rem

func rem(x : Nat16, y : Nat16) : Nat16

The function rem takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 400;
let y : Nat16 = 150;

Nat16.rem(x, y);

Nat16.pow

func pow(x : Nat16, y : Nat16) : Nat16

The function pow takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 10;
let y : Nat16 = 4;

Nat16.pow(x, y);

Nat16.bitnot

func bitnot(x : Nat16) : Nat16

The function bitnot takes one Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 65520; // Binary : 11111111_11110000

Nat16.bitnot(x) // Binary : 00000000_00001111

Nat16.bitand

func bitand(x : Nat16, y : Nat16) : Nat16

The function bitand takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 65530; // Binary : 11111111_11111111
let y : Nat16 = 5; // Binary : 00000000_00000101

Nat16.bitand(x, y) // Binary : 00000000_00000101

Nat16.bitor

func bitor(x : Nat16, y : Nat16) : Nat16

The function bitor takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 240; // Binary : 00000000_11110000
let y : Nat16 = 15; // Binary : 00000000_00001111

Nat16.bitor(x, y) // Binary : 00000000_11111111

Nat16.bitxor

func bitxor(x : Nat16, y : Nat16) : Nat16

The function bitxor takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 255; // Binary : 00000000_11111111
let y : Nat16 = 240; // Binary : 00000000_11110000

Nat16.bitxor(x, y) // Binary : 00000000_00001111

Nat16.bitshiftLeft

func bitshiftLeft(x : Nat16, y : Nat16) : Nat16

The function bitshiftLeft takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 15; // Binary : 00000000_00001111
let y : Nat16 = 4;

Nat16.bitshiftLeft(x, y) // Binary : 00000000_11110000

Nat16.bitshiftRight

func bitshiftRight(x : Nat16, y : Nat16) : Nat16

The function bitshiftRight takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 240; // Binary : 00000000_11110000
let y : Nat16 = 4;

Nat16.bitshiftRight(x, y) // Binary : 00000000_00001111

Nat16.bitrotLeft

func bitrotLeft(x : Nat16, y : Nat16) : Nat16

The function bitrotLeft takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 32768; // Binary : 10000000_00000000
let y : Nat16 = 1;

Nat16.bitrotLeft(x, y) // Binary : 00000000_00000001

Nat16.bitrotRight

func bitrotRight(x : Nat16, y : Nat16) : Nat16

The function bitrotRight takes two Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 1; // Binary : 00000000_00000001
let y : Nat16 = 1;

Nat16.bitrotRight(x, y) // Binary : 10000000_00000000

Nat16.bittest

func bittest(x : Nat16, p : Nat) : Bool

The function bittest takes one Nat16 and one Nat value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 255; // Binary : 00000000_11111111
let p : Nat = 7;

Nat16.bittest(x, p)

Nat16.bitset

func bitset(x : Nat16, p : Nat) : Bool

The function bitset takes one Nat16 and one Nat value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 127; // Binary : 00000000_01111111
let p : Nat = 7;

Nat16.bitset(x, p) // Binary : 00000000_11111111

Nat16.bitclear

func bitclear(x : Nat16, p : Nat) : Bool

The function bitclear takes one Nat16 and one Nat value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 255; // Binary : 00000000_11111111
let p : Nat = 7;

Nat16.bitclear(x, p) // Binary : 00000000_01111111

Nat16.bitflip

func bitflip(x : Nat16, p : Nat) : Bool

The function bitflip takes one Nat16 and one Nat value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 255; // Binary : 00000000_11111111
let p : Nat = 7;

Nat16.bitflip(x, p) // Binary : 00000000_01111111

Nat16.bitcountNonZero

let bitcountNonZero : (x : Nat16) -> Nat16

The function bitcountNonZero takes one Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 255; // Binary : 00000000_11111111

Nat16.bitcountNonZero(x)

Nat16.bitcountLeadingZero

let bitcountLeadingZero : (x : Nat16) -> Nat16

The function bitcountLeadingZero takes one Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 255; // Binary : 00000000_11111111

Nat16.bitcountLeadingZero(x)

Nat16.bitcountTrailingZero

let bitcountTrailingZero : (x : Nat16) -> Nat16

The function bitcountTrailingZero takes one Nat16 value and returns a Nat16 value.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 128; // Binary : 00000000_10000000

Nat16.bitcountTrailingZero(x)

Nat16.addWrap

func addWrap(x : Nat16, y : Nat16) : Nat16

The function addWrap takes two Nat16 value and returns a Nat16 value.It is equivalent to the +% Bitwise operators.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 65535;
let y : Nat16 = 2;

Nat16.addWrap(x, y)

Nat16.subWrap

func subWrap(x : Nat16, y : Nat16) : Nat16

The function subWrap takes two Nat16 value and returns a Nat16 value.It is equivalent to the -% Bitwise operators.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 0;
let y : Nat16 = 2;

Nat16.subWrap(x, y)

Nat16.mulWrap

func mulWrap(x : Nat16, y : Nat16) : Nat16

The function mulWrap takes two Nat16 value and returns a Nat16 value.It is equivalent to the *% Bitwise operators.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 256;
let y : Nat16 = 256;

Nat16.mulWrap(x, y)

Nat16.powWrap

func powWrap(x : Nat16, y : Nat16) : Nat16

The function powWrap takes two Nat16 value and returns a Nat16 value.It is equivalent to the **% Bitwise operators.

import Nat16 "mo:base/Nat16";

let x : Nat16 = 256;
let y : Nat16 = 2;

Nat16.powWrap(x, y)