Int8
The convention is to name the module alias after the file name it is defined in:
import Int8 "mo:base/Int8";
On this page
Constants
Value minimumValue
Value maximumValue
Conversion
Function toInt
Function toText
Function fromInt
Function fromIntWrap
Function fromNat8
Function toNat8
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 : Int8 = -128
maximumValue
let maximumValue : Int8 = 127
Int8.toInt
func toInt(i : Int8) : Int
The function toInt
takes one Int8
value and returns an Int
value.
import Int8 "mo:base/Int8";
let a : Int8 = -127;
Int8.toInt(a);
Int8.toText
func toText(i : Int8) : Text
The function toText
takes one Int8
value and returns a Text
value.
import Int8 "mo:base/Int8";
let b : Int8 = -127;
Int8.toText(b);
Int8.fromInt
func fromInt(i : Int) : Int8
The function fromInt
takes one Int
value and returns an Int8
value.
import Int8 "mo:base/Int8";
let integer : Int = -127;
Int8.fromInt(integer);
Int8.fromIntWrap
func fromIntWrap(i : Int) : Int8
The function fromIntWrap
takes one Int
value and returns an Int8
value.
import Int8 "mo:base/Int8";
let integer : Int = 255;
Int8.fromIntWrap(integer);
Int8.fromNat8
func fromNat8(i : Nat8) : Int8
The function fromNat8
takes one Nat8
value and returns an Int8
value.
import Int8 "mo:base/Int8";
let Nat8 : Nat8 = 127;
Int8.fromNat8(Nat8);
Int8.toNat8
func toNat8(i : Int8) : Nat8
The function toNat8
takes one Int8
value and returns an Nat8
value.
import Int8 "mo:base/Int8";
let int8 : Int8 = -127;
Int8.toNat8(int8);
Int8.min
func min(x : Int8, y : Int8) : Int8
The function min
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 15;
let y : Int8 = -10;
Int8.min(x, y);
Int8.max
func max(x : Int8, y : Int8) : Int8
The function max
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 15;
let y : Int8 = -15;
Int8.max(x, y);
Int8.equal
func equal(x : Int8, y : Int8) : Bool
The function equal
takes two Int8
value and returns a Bool
value.
import Int8 "mo:base/Int8";
let x : Int8 = 10;
let y : Int8 = 10;
Int8.equal(x, y);
Int8.notEqual
func notEqual(x : Int8, y : Int8) : Bool
The function notEqual
takes two Int8
value and returns a Bool
value.
import Int8 "mo:base/Int8";
let x : Int8 = -10;
let y : Int8 = 10;
Int8.notEqual(x, y);
Int8.less
func less(x : Int8, y : Int8) : Bool
The function less
takes two Int8
value and returns a Bool
value.
import Int8 "mo:base/Int8";
let x : Int8 = -15;
let y : Int8 = -25;
Int8.less(x, y);
Int8.lessOrEqual
func lessOrEqual(x : Int8, y : Int8) : Bool
The function lessOrEqual
takes two Int8
value and returns a Bool
value.
import Int8 "mo:base/Int8";
let x : Int8 = -15;
let y : Int8 = -25;
Int8.lessOrEqual(x, y);
Int8.greater
func greater(x : Int8, y : Int8) : Bool
The function greater
takes two Int8
value and returns a Bool
value.
import Int8 "mo:base/Int8";
let x : Int8 = -15;
let y : Int8 = -10;
Int8.greater(x, y);
Int8.greaterOrEqual
func greaterOrEqual(x : Int8, y : Int8) : Bool
The function greaterOrEqual
takes two Int8
value and returns a Bool
value.
import Int8 "mo:base/Int8";
let x : Int8 = 15;
let y : Int8 = 10;
Int8.greaterOrEqual(x, y);
Int8.compare
func compare(x : Int8, y : Int8) : Bool
The function compare
takes two Int8
value and returns an Order variant value.
import Int8 "mo:base/Int8";
let x : Int8 = -15;
let y : Int8 = -10;
Int8.compare(x, y);
Int8.abs
func abs(x : Int8) : Int8
The function abs
takes one Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = -40;
Int8.abs(x);
Int8.neg
func neg(x : Int8) : Int8
The function neg
takes one Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = -50;
Int8.neg(x);
Int8.add
func add(x : Int8, y : Int8) : Int8
The function add
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = -40;
let y : Int8 = 10;
Int8.add(x, y);
Int8.sub
func sub(x : Int8, y : Int8) : Int8
The function sub
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = -40;
let y : Int8 = -50;
Int8.sub(x, y);
Int8.mul
func mul(x : Int8, y : Int8) : Int8
The function mul
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 20;
let y : Int8 = -5;
Int8.mul(x, y);
Int8.div
func div(x : Int8, y : Int8) : Int8
The function div
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 50;
let y : Int8 = -10;
Int8.div(x, y);
Int8.rem
func rem(x : Int8, y : Int8) : Int8
The function rem
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = -40;
let y : Int8 = 15;
Int8.rem(x, y);
Int8.pow
func pow(x : Int8, y : Int8) : Int8
The function pow
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = -5;
let y : Int8 = 3;
Int8.pow(x, y);
Int8.bitnot
func bitnot(x : Int8) : Int8
The function bitnot
takes one Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 127; // Binary : 01111111
Int8.bitnot(x) // Binary : 10000000
Int8.bitand
func bitand(x : Int8, y : Int8) : Int8
The function bitand
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 127; // Binary : 01111111
let y : Int8 = 15; // Binary : 00001111
Int8.bitand(x, y)
Int8.bitor
func bitor(x : Int8, y : Int8) : Int8
The function bitor
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 112; // Binary : 01110000
let y : Int8 = 15; // Binary : 00001111
Int8.bitor(x, y) // Binary : 01111111
Int8.bitxor
func bitxor(x : Int8, y : Int8) : Int8
The function bitxor
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 15; // Binary : 00001111
let y : Int8 = 14; // Binary : 00001110
Int8.bitxor(x, y) // Binary : 00000001
Int8.bitshiftLeft
func bitshiftLeft(x : Int8, y : Int8) : Int8
The function bitshiftLeft
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 15; // Binary : 00001111
let y : Int8 = 4;
Int8.bitshiftLeft(x, y) // Binary : 11110000
Int8.bitshiftRight
func bitshiftRight(x : Int8, y : Int8) : Int8
The function bitshiftRight
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 48; // Binary : 00110000
let y : Int8 = 2;
Int8.bitshiftRight(x, y) // Binary : 00001100
Int8.bitrotLeft
func bitrotLeft(x : Int8, y : Int8) : Int8
The function bitrotLeft
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 15; // Binary : 00001111
let y : Int8 = 4;
Int8.bitrotLeft(x, y) // Binary : 11110000
Int8.bitrotRight
func bitrotRight(x : Int8, y : Int8) : Int8
The function bitrotRight
takes two Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 48; // Binary : 00110000
let y : Int8 = 2;
Int8.bitrotRight(x, y) // Binary : 00001100
Int8.bittest
func bittest(x : Int8, p : Nat) : Bool
The function bittest
takes one Int8
and one Nat
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 12; // Binary : 00001100
let p : Nat = 2;
Int8.bittest(x, p)
Int8.bitset
func bitset(x : Int8, p : Nat) : Bool
The function bitset
takes one Int8
and one Nat
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 12; // Binary : 00001100
let p : Nat = 4;
Int8.bitset(x, p) // Binary : 00011100
Int8.bitclear
func bitclear(x : Int8, p : Nat) : Bool
The function bitclear
takes one Int8
and one Nat
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 12; // Binary : 00001100
let p : Nat = 3;
Int8.bitclear(x, p) // Binary : 00000100
Int8.bitflip
func bitflip(x : Int8, p : Nat) : Bool
The function bitflip
takes one Int8
and one Nat
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 12; // Binary : 00001100
let p : Nat = 4;
Int8.bitflip(x, p) // Binary : 00011100
Int8.bitcountNonZero
let bitcountNonZero : (x : Int8) -> Int8
The function bitcountNonZero
takes one Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 15; // Binary : 00001111
Int8.bitcountNonZero(x)
Int8.bitcountLeadingZero
let bitcountLeadingZero : (x : Int8) -> Int8
The function bitcountLeadingZero
takes one Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 12; // Binary : 00001100
Int8.bitcountLeadingZero(x)
Int8.bitcountTrailingZero
let bitcountTrailingZero : (x : Int8) -> Int8
The function bitcountTrailingZero
takes one Int8
value and returns a Int8
value.
import Int8 "mo:base/Int8";
let x : Int8 = 48; // Binary : 00110000
Int8.bitcountTrailingZero(x)
Int8.addWrap
func addWrap(x : Int8, y : Int8) : Int8
The function addWrap
takes two Int8
value and returns a Int8
value.It is equivalent to the +%
Bitwise operators.
import Int8 "mo:base/Int8";
let x : Int8 = 127;
let y : Int8 = 2;
Int8.addWrap(x, y)
Int8.subWrap
func subWrap(x : Int8, y : Int8) : Int8
The function subWrap
takes two Int8
value and returns a Int8
value.It is equivalent to the -%
Bitwise operators.
import Int8 "mo:base/Int8";
let x : Int8 = -128;
let y : Int8 = 2;
Int8.subWrap(x, y)
Int8.mulWrap
func mulWrap(x : Int8, y : Int8) : Int8
The function mulWrap
takes two Int8
value and returns a Int8
value.It is equivalent to the *%
Bitwise operators.
import Int8 "mo:base/Int8";
let x : Int8 = 127;
let y : Int8 = 2;
Int8.mulWrap(x, y)
Int8.powWrap
func powWrap(x : Int8, y : Int8) : Int8
The function powWrap
takes two Int8
value and returns a Int8
value.It is equivalent to the **%
Bitwise operators.
import Int8 "mo:base/Int8";
let x : Int8 = 6;
let y : Int8 = 3;
Int8.powWrap(x, y)