Nat32
The convention is to name the module alias after the file name it is defined in:
import Nat32 "mo:base/Nat32";
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 : Nat32 = 0;
maximumValue
let maximumValue : Nat32 = 4_294_967_295;
Nat32.toNat
func toNat(i : Nat32) : Nat
The function toNat
takes one Nat32
value and returns a Nat
value.
import Nat32 "mo:base/Nat32";
let a : Nat32 = 4294967295;
Nat32.toNat(a);
Nat32.toText
func toText(i : Nat32) : Text
The function toText
takes one Nat32
value and returns a Text
value.
import Nat32 "mo:base/Nat32";
let b : Nat32 = 4294967295;
Nat32.toText(b);
Nat32.fromNat
func fromNat(i : Nat) : Nat32
The function fromNat
takes one Nat
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let number : Nat = 4294967295;
Nat32.fromNat(number);
Nat32.fromIntWrap
func fromIntWrap(i : Int) : Nat32
The function fromIntWrap
takes one Int
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let integer : Int = 4294967295;
Nat32.fromIntWrap(integer);
Nat32.min
func min(x : Nat32, y : Nat32) : Nat32
The function min
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 2000;
let y : Nat32 = 1001;
Nat32.min(x, y);
Nat32.max
func max(x : Nat32, y : Nat32) : Nat32
The function max
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 2000;
let y : Nat32 = 2001;
Nat32.max(x, y);
Nat32.equal
func equal(x : Nat32, y : Nat32) : Bool
The function equal
takes two Nat32
value and returns a Bool
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 1000;
let y : Nat32 = 100;
Nat32.equal(x, y);
Nat32.notEqual
func notEqual(x : Nat32, y : Nat32) : Bool
The function notEqual
takes two Nat32
value and returns a Bool
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 1000;
let y : Nat32 = 1001;
Nat32.notEqual(x, y);
Nat32.less
func less(x : Nat32, y : Nat32) : Bool
The function less
takes two Nat32
value and returns a Bool
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 2000;
let y : Nat32 = 2500;
Nat32.less(x, y);
Nat32.lessOrEqual
func lessOrEqual(x : Nat32, y : Nat32) : Bool
The function lessOrEqual
takes two Nat32
value and returns a Bool
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 2000;
let y : Nat32 = 2500;
Nat32.lessOrEqual(x, y);
Nat32.greater
func greater(x : Nat32, y : Nat32) : Bool
The function greater
takes two Nat32
value and returns a Bool
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 2000;
let y : Nat32 = 1000;
Nat32.greater(x, y);
Nat32.greaterOrEqual
func greaterOrEqual(x : Nat32, y : Nat32) : Bool
The function greaterOrEqual
takes two Nat32
value and returns a Bool
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 2000;
let y : Nat32 = 1000;
Nat32.greaterOrEqual(x, y);
Nat32.compare
func compare(x : Nat32, y : Nat32) : Bool
The function compare
takes two Nat32
value and returns an Order variant value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 10000;
let y : Nat32 = 9999;
Nat32.compare(x, y);
Nat32.add
func add(x : Nat32, y : Nat32) : Nat32
The function add
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 2000;
let y : Nat32 = 1200;
Nat32.add(x, y);
Nat32.sub
func sub(x : Nat32, y : Nat32) : Nat32
The function sub
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 4000;
let y : Nat32 = 3999;
Nat32.sub(x, y);
Nat32.mul
func mul(x : Nat32, y : Nat32) : Nat32
The function mul
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 200;
let y : Nat32 = 50;
Nat32.mul(x, y);
Nat32.div
func div(x : Nat32, y : Nat32) : Nat32
The function div
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 5000;
let y : Nat32 = 500;
Nat32.div(x, y);
Nat32.rem
func rem(x : Nat32, y : Nat32) : Nat32
The function rem
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 4000;
let y : Nat32 = 1200;
Nat32.rem(x, y);
Nat32.pow
func pow(x : Nat32, y : Nat32) : Nat32
The function pow
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 10;
let y : Nat32 = 5;
Nat32.pow(x, y);
Nat32.bitnot
func bitnot(x : Nat32) : Nat32
The function bitnot
takes one Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 4294967040; // Binary : 11111111_11111111_11111111_00000000
Nat32.bitnot(x) // Binary : 00000000_00000000_00000000_11111111
Nat32.bitand
func bitand(x : Nat32, y : Nat32) : Nat32
The function bitand
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 4294967295; // Binary : 11111111_11111111_11111111_11111111
let y : Nat32 = 255; // Binary : 00000000_00000000_00000000_11111111
Nat32.bitand(x, y) // Binary : 00000000_00000000_00000000_11111111
Nat32.bitor
func bitor(x : Nat32, y : Nat32) : Nat32
The function bitor
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 240; // Binary : 00000000_00000000_00000000_11110000
let y : Nat32 = 15; // Binary : 00000000_00000000_00000000_00001111
Nat32.bitor(x, y) // Binary : 00000000_00000000_00000000_11111111
Nat32.bitxor
func bitxor(x : Nat32, y : Nat32) : Nat32
The function bitxor
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 255; // Binary : 00000000_00000000_00000000_11111111
let y : Nat32 = 240; // Binary : 00000000_00000000_00000000_11110000
Nat32.bitxor(x, y) // Binary : 00000000_00000000_00000000_00001111
Nat32.bitshiftLeft
func bitshiftLeft(x : Nat32, y : Nat32) : Nat32
The function bitshiftLeft
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 15; // Binary : 00000000_00000000_00000000_00001111
let y : Nat32 = 4;
Nat32.bitshiftLeft(x, y) // Binary : 00000000_00000000_00000000_11110000
Nat32.bitshiftRight
func bitshiftRight(x : Nat32, y : Nat32) : Nat32
The function bitshiftRight
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 240; // Binary : 00000000_00000000_00000000_11110000
let y : Nat32 = 4;
Nat32.bitshiftRight(x, y) // Binary : 00000000_00000000_00000000_00001111
Nat32.bitrotLeft
func bitrotLeft(x : Nat32, y : Nat32) : Nat32
The function bitrotLeft
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 4_278_190_080; // Binary : 11111111_00000000_00000000_00000000
let y : Nat32 = 8;
Nat32.bitrotLeft(x, y) // Binary : 00000000_00000000_00000000_11111111
Nat32.bitrotRight
func bitrotRight(x : Nat32, y : Nat32) : Nat32
The function bitrotRight
takes two Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 255; // Binary : 00000000_00000000_00000000_11111111
let y : Nat32 = 8;
Nat32.bitrotRight(x, y) // Binary : 11111111_00000000_00000000_00000000
Nat32.bittest
func bittest(x : Nat32, p : Nat) : Bool
The function bittest
takes one Nat32
and one Nat
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 255; // Binary : 00000000_00000000_00000000_11111111
let p : Nat = 7;
Nat32.bittest(x, p)
Nat32.bitset
func bitset(x : Nat32, p : Nat) : Bool
The function bitset
takes one Nat32
and one Nat
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 127; // Binary : 00000000_00000000_00000000_01111111
let p : Nat = 7;
Nat32.bitset(x, p) // Binary : 00000000_00000000_00000000_11111111
Nat32.bitclear
func bitclear(x : Nat32, p : Nat) : Bool
The function bitclear
takes one Nat32
and one Nat
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 255; // Binary : 00000000_00000000_00000000_11111111
let p : Nat = 7;
Nat32.bitclear(x, p) // Binary : 00000000_00000000_00000000_01111111
Nat32.bitflip
func bitflip(x : Nat32, p : Nat) : Bool
The function bitflip
takes one Nat32
and one Nat
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 255; // Binary : 00000000_00000000_00000000_11111111
let p : Nat = 7;
Nat32.bitflip(x, p) // Binary : 00000000_00000000_00000000_01111111
Nat32.bitcountNonZero
let bitcountNonZero : (x : Nat32) -> Nat32
The function bitcountNonZero
takes one Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 255; // Binary : 00000000_00000000_00000000_11111111
Nat32.bitcountNonZero(x)
Nat32.bitcountLeadingZero
let bitcountLeadingZero : (x : Nat32) -> Nat32
The function bitcountLeadingZero
takes one Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 255; // Binary : 00000000_00000000_00000000_11111111
Nat32.bitcountLeadingZero(x)
Nat32.bitcountTrailingZero
let bitcountTrailingZero : (x : Nat32) -> Nat32
The function bitcountTrailingZero
takes one Nat32
value and returns a Nat32
value.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 128; // Binary : 00000000_00000000_00000000_10000000
Nat32.bitcountTrailingZero(x)
Nat32.addWrap
func addWrap(x : Nat32, y : Nat32) : Nat32
The function addWrap
takes two Nat32
value and returns a Nat32
value.It is equivalent to the +%
Bitwise operators.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 4294967295;
let y : Nat32 = 1;
Nat32.addWrap(x, y)
Nat32.subWrap
func subWrap(x : Nat32, y : Nat32) : Nat32
The function subWrap
takes two Nat32
value and returns a Nat32
value.It is equivalent to the -%
Bitwise operators.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 0;
let y : Nat32 = 2;
Nat32.subWrap(x, y)
Nat32.mulWrap
func mulWrap(x : Nat32, y : Nat32) : Nat32
The function mulWrap
takes two Nat32
value and returns a Nat32
value.It is equivalent to the *%
Bitwise operators.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 65536;
let y : Nat32 = 65536;
Nat32.mulWrap(x, y)
Nat32.powWrap
func powWrap(x : Nat32, y : Nat32) : Nat32
The function powWrap
takes two Nat32
value and returns a Nat32
value.It is equivalent to the **%
Bitwise operators.
import Nat32 "mo:base/Nat32";
let x : Nat32 = 65536;
let y : Nat32 = 2;
Nat32.powWrap(x, y)