Int32
The convention is to name the module alias after the file name it is defined in:
import Int32 "mo:base/Int32";
On this page
Constants
Value minimumValue
Value maximumValue
Conversion
Function toInt
Function toText
Function fromInt
Function fromIntWrap
Function fromNat32
Function toNat32
Comparison
Function min
Function max
Function equal
Function notEqual
Function less
Function lessOrEqual
Function greater
Function greaterOrEqual
Function compare
Numerical Operations
Function abs
Function neg
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 : Int32 = -2_147_483_648
maximumValue
let maximumValue : Int32 = 2_147_483_647
Int32.toInt
func toInt(i : Int32) : Int
The function toInt
takes one Int32
value and returns an Int
value.
import Int32 "mo:base/Int32";
let a : Int32 = -2147483648;
Int32.toInt(a);
Int32.toText
func toText(i : Int32) : Text
The function toText
takes one Int32
value and returns a Text
value.
import Int32 "mo:base/Int32";
let b : Int32 = -2147483648;
Int32.toText(b);
Int32.fromInt
func fromInt(i : Int) : Int32
The function fromInt
takes one Int
value and returns an Int32
value.
import Int32 "mo:base/Int32";
let integer : Int = -21474;
Int32.fromInt(integer);
Int32.fromIntWrap
func fromIntWrap(i : Int) : Int32
The function fromIntWrap
takes one Int
value and returns an Int32
value.
import Int32 "mo:base/Int32";
let integer : Int = 4294967295;
Int32.fromIntWrap(integer);
Int32.fromNat32
func fromNat32(i : Nat32) : Int32
The function fromNat32
takes one Nat32
value and returns an Int32
value.
import Int32 "mo:base/Int32";
let nat32 : Nat32 = 4294967295;
Int32.fromNat32(nat32);
Int32.toNat32
func toNat32(i : Int32) : Nat32
The function toNat32
takes one Int32
value and returns an Nat32
value.
import Int32 "mo:base/Int32";
let int32 : Int32 = -967296;
Int32.toNat32(int32);
Int32.min
func min(x : Int32, y : Int32) : Int32
The function min
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 2000;
let y : Int32 = 1001;
Int32.min(x, y);
Int32.max
func max(x : Int32, y : Int32) : Int32
The function max
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 2000;
let y : Int32 = 2001;
Int32.max(x, y);
Int32.equal
func equal(x : Int32, y : Int32) : Bool
The function equal
takes two Int32
value and returns a Bool
value.
import Int32 "mo:base/Int32";
let x : Int32 = 1000;
let y : Int32 = 100;
Int32.equal(x, y);
Int32.notEqual
func notEqual(x : Int32, y : Int32) : Bool
The function notEqual
takes two Int32
value and returns a Bool
value.
import Int32 "mo:base/Int32";
let x : Int32 = 1000;
let y : Int32 = 1001;
Int32.notEqual(x, y);
Int32.less
func less(x : Int32, y : Int32) : Bool
The function less
takes two Int32
value and returns a Bool
value.
import Int32 "mo:base/Int32";
let x : Int32 = 2000;
let y : Int32 = 2500;
Int32.less(x, y);
Int32.lessOrEqual
func lessOrEqual(x : Int32, y : Int32) : Bool
The function lessOrEqual
takes two Int32
value and returns a Bool
value.
import Int32 "mo:base/Int32";
let x : Int32 = 2000;
let y : Int32 = 2500;
Int32.lessOrEqual(x, y);
Int32.greater
func greater(x : Int32, y : Int32) : Bool
The function greater
takes two Int32
value and returns a Bool
value.
import Int32 "mo:base/Int32";
let x : Int32 = 2000;
let y : Int32 = 1000;
Int32.greater(x, y);
Int32.greaterOrEqual
func greaterOrEqual(x : Int32, y : Int32) : Bool
The function greaterOrEqual
takes two Int32
value and returns a Bool
value.
import Int32 "mo:base/Int32";
let x : Int32 = 2000;
let y : Int32 = 1000;
Int32.greaterOrEqual(x, y);
Int32.compare
func compare(x : Int32, y : Int32) : Bool
The function compare
takes two Int32
value and returns an Order variant value.
import Int32 "mo:base/Int32";
let x : Int32 = 10000;
let y : Int32 = 9999;
Int32.compare(x, y);
Int32.abs
func abs(x : Int32) : Int32
The function abs
takes one Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = -40;
Int32.abs(x);
Int32.neg
func neg(x : Int32) : Int32
The function neg
takes one Int32
value and returns a Int32
value.
import Int8 "mo:base/Int8";
let x : Int8 = -50;
Int8.neg(x);
Int32.add
func add(x : Int32, y : Int32) : Int32
The function add
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 2000;
let y : Int32 = 1200;
Int32.add(x, y);
Int32.sub
func sub(x : Int32, y : Int32) : Int32
The function sub
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 4000;
let y : Int32 = 3999;
Int32.sub(x, y);
Int32.mul
func mul(x : Int32, y : Int32) : Int32
The function mul
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 200;
let y : Int32 = 50;
Int32.mul(x, y);
Int32.div
func div(x : Int32, y : Int32) : Int32
The function div
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 5000;
let y : Int32 = 500;
Int32.div(x, y);
Int32.rem
func rem(x : Int32, y : Int32) : Int32
The function rem
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 4000;
let y : Int32 = 1200;
Int32.rem(x, y);
Int32.pow
func pow(x : Int32, y : Int32) : Int32
The function pow
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 10;
let y : Int32 = 5;
Int32.pow(x, y);
Int32.bitnot
func bitnot(x : Int32) : Int32
The function bitnot
takes one Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 255; // Binary : 00000000_00000000_00000000_11111111
Int32.bitnot(x) // Binary : 11111111_11111111_11111111_00000000
Int32.bitand
func bitand(x : Int32, y : Int32) : Int32
The function bitand
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 255; // Binary : 00000000_00000000_00000000_11111111
let y : Int32 = 255; // Binary : 00000000_00000000_00000000_11111111
Int32.bitand(x, y) // Binary : 00000000_00000000_00000000_11111111
Int32.bitor
func bitor(x : Int32, y : Int32) : Int32
The function bitor
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 240; // Binary : 00000000_00000000_00000000_11110000
let y : Int32 = 15; // Binary : 00000000_00000000_00000000_00001111
Int32.bitor(x, y) // Binary : 00000000_00000000_00000000_11111111
Int32.bitxor
func bitxor(x : Int32, y : Int32) : Int32
The function bitxor
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 255; // Binary : 00000000_00000000_00000000_11111111
let y : Int32 = 240; // Binary : 00000000_00000000_00000000_11110000
Int32.bitxor(x, y) // Binary : 00000000_00000000_00000000_00001111
Int32.bitshiftLeft
func bitshiftLeft(x : Int32, y : Int32) : Int32
The function bitshiftLeft
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 15; // Binary : 00000000_00000000_00000000_00001111
let y : Int32 = 4;
Int32.bitshiftLeft(x, y) // Binary : 00000000_00000000_00000000_11110000
Int32.bitshiftRight
func bitshiftRight(x : Int32, y : Int32) : Int32
The function bitshiftRight
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 240; // Binary : 00000000_00000000_00000000_11110000
let y : Int32 = 4;
Int32.bitshiftRight(x, y) // Binary : 00000000_00000000_00000000_00001111
Int32.bitrotLeft
func bitrotLeft(x : Int32, y : Int32) : Int32
The function bitrotLeft
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 2_147_483_647; // Binary : 01111111_11111111_11111111_11111111
let y : Int32 = 1;
Int32.bitrotLeft(x, y) // Binary : 11111111_11111111_11111111_11111110
Int32.bitrotRight
func bitrotRight(x : Int32, y : Int32) : Int32
The function bitrotRight
takes two Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 2_147_483_647; // Binary : 01111111_11111111_11111111_11111111
let y : Int32 = 1;
Int32.bitrotRight(x, y) // Binary : 10111111_11111111_11111111_11111111
Int32.bittest
func bittest(x : Int32, p : Nat) : Bool
The function bittest
takes one Int32
and one Nat
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 255; // Binary : 00000000_00000000_00000000_11111111
let p : Nat = 7;
Int32.bittest(x, p)
Int32.bitset
func bitset(x : Int32, p : Nat) : Bool
The function bitset
takes one Int32
and one Nat
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 127; // Binary : 00000000_00000000_00000000_01111111
let p : Nat = 7;
Int32.bitset(x, p) // Binary : 00000000_00000000_00000000_11111111
Int32.bitclear
func bitclear(x : Int32, p : Nat) : Bool
The function bitclear
takes one Int32
and one Nat
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 255; // Binary : 00000000_00000000_00000000_11111111
let p : Nat = 7;
Int32.bitclear(x, p) // Binary : 00000000_00000000_00000000_01111111
Int32.bitflip
func bitflip(x : Int32, p : Nat) : Bool
The function bitflip
takes one Int32
and one Nat
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 255; // Binary : 00000000_00000000_00000000_11111111
let p : Nat = 7;
Int32.bitflip(x, p) // Binary : 00000000_00000000_00000000_01111111
Int32.bitcountNonZero
let bitcountNonZero : (x : Int32) -> Int32
The function bitcountNonZero
takes one Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 255; // Binary : 00000000_00000000_00000000_11111111
Int32.bitcountNonZero(x)
Int32.bitcountLeadingZero
let bitcountLeadingZero : (x : Int32) -> Int32
The function bitcountLeadingZero
takes one Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 255; // Binary : 00000000_00000000_00000000_11111111
Int32.bitcountLeadingZero(x)
Int32.bitcountTrailingZero
let bitcountTrailingZero : (x : Int32) -> Int32
The function bitcountTrailingZero
takes one Int32
value and returns a Int32
value.
import Int32 "mo:base/Int32";
let x : Int32 = 128; // Binary : 00000000_00000000_00000000_10000000
Int32.bitcountTrailingZero(x)
Int32.addWrap
func addWrap(x : Int32, y : Int32) : Int32
The function addWrap
takes two Int32
value and returns a Int32
value.It is equivalent to the +%
Bitwise operators.
import Int32 "mo:base/Int32";
let x : Int32 = 2_147_483_647;
let y : Int32 = 1;
Int32.addWrap(x, y)
Int32.subWrap
func subWrap(x : Int32, y : Int32) : Int32
The function subWrap
takes two Int32
value and returns a Int32
value.It is equivalent to the -%
Bitwise operators.
import Int32 "mo:base/Int32";
let x : Int32 = -2_147_483_648;
let y : Int32 = 1;
Int32.subWrap(x, y)
Int32.mulWrap
func mulWrap(x : Int32, y : Int32) : Int32
The function mulWrap
takes two Int32
value and returns a Int32
value.It is equivalent to the *%
Bitwise operators.
import Int32 "mo:base/Int32";
let x : Int32 = 2_147_483_647;
let y : Int32 = 2;
Int32.mulWrap(x, y)
Int32.powWrap
func powWrap(x : Int32, y : Int32) : Int32
The function powWrap
takes two Int32
value and returns a Int32
value.It is equivalent to the **%
Bitwise operators.
import Int32 "mo:base/Int32";
let x : Int32 = 65536;
let y : Int32 = 2;
Int32.powWrap(x, y)