Nat8

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

import Nat8 "mo:base/Nat8";

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 : Nat8 = 0

maximumValue

let maximumValue : Nat8 = 255

Nat8.toNat

func toNat(i : Nat8) : Nat

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

import Nat8 "mo:base/Nat8";

let a : Nat8 = 255;

Nat8.toNat(a);

Nat8.toText

func toText(i : Nat8) : Text

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

import Nat8 "mo:base/Nat8";

let b : Nat8 = 255;

Nat8.toText(b);

Nat8.fromNat

func fromNat(i : Nat) : Nat8

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

import Nat8 "mo:base/Nat8";

let c : Nat = 255;

Nat8.fromNat(c);

Nat8.fromIntWrap

func fromIntWrap(i : Int) : Nat8

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

import Nat8 "mo:base/Nat8";

let integer : Int = 356;

Nat8.fromIntWrap(integer);

Nat8.min

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 15;
let y : Nat8 = 10;

Nat8.min(x, y);

Nat8.max

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 15;
let y : Nat8 = 10;

Nat8.max(x, y);

Nat8.equal

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 10;
let y : Nat8 = 10;

Nat8.equal(x, y);

Nat8.notEqual

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 15;
let y : Nat8 = 10;

Nat8.notEqual(x, y);

Nat8.less

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 15;
let y : Nat8 = 25;

Nat8.less(x, y);

Nat8.lessOrEqual

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 15;
let y : Nat8 = 25;

Nat8.lessOrEqual(x, y);

Nat8.greater

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 15;
let y : Nat8 = 10;

Nat8.greater(x, y);

Nat8.greaterOrEqual

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 15;
let y : Nat8 = 10;

Nat8.greaterOrEqual(x, y);

Nat8.compare

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 10;
let y : Nat8 = 10;

Nat8.compare(x, y);

Nat8.add

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 40;
let y : Nat8 = 10;

Nat8.add(x, y);

Nat8.sub

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 40;
let y : Nat8 = 20;

Nat8.sub(x, y);

Nat8.mul

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 20;
let y : Nat8 = 10;

Nat8.mul(x, y);

Nat8.div

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 50;
let y : Nat8 = 10;

Nat8.div(x, y);

Nat8.rem

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 40;
let y : Nat8 = 15;

Nat8.rem(x, y);

Nat8.pow

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 6;
let y : Nat8 = 3;

Nat8.pow(x, y);

Nat8.bitnot

func bitnot(x : Nat8) : Nat8

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 254; // Binary : 11111110

Nat8.bitnot(x) // Binary : 00000001

Nat8.bitand

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 255; // Binary : 11111111
let y : Nat8 = 15; // Binary : 00001111

Nat8.bitand(x, y) // Binary : 00001111

Nat8.bitor

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 240; // Binary : 11110000
let y : Nat8 = 15; // Binary : 00001111

Nat8.bitor(x, y) // Binary : 11111111

Nat8.bitxor

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 15; // Binary : 00001111
let y : Nat8 = 3; // Binary : 00000011

Nat8.bitxor(x, y) // Binary : 00001100

Nat8.bitshiftLeft

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 48; // Binary : 00110000
let y : Nat8 = 2;

Nat8.bitshiftLeft(x, y) // Binary : 11000000

Nat8.bitshiftRight

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 12; // Binary : 00001100
let y : Nat8 = 2;

Nat8.bitshiftRight(x, y) // Binary : 00000011

Nat8.bitrotLeft

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 240; // Binary : 11110000
let y : Nat8 = 2;

Nat8.bitrotLeft(x, y) // Binary : 11000011

Nat8.bitrotRight

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 15; // Binary : 00001111
let y : Nat8 = 2;

Nat8.bitrotRight(x, y) // Binary : 11000011

Nat8.bittest

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 12; // Binary : 00001100
let p : Nat = 2;

Nat8.bittest(x, p)

Nat8.bitset

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 12; // Binary : 00001100
let p : Nat = 1;

Nat8.bitset(x, p) // Binary : 00001110

Nat8.bitclear

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 12; // Binary : 00001100
let p : Nat = 3;

Nat8.bitclear(x, p) // Binary : 00000100

Nat8.bitflip

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 12; // Binary : 00001100
let p : Nat = 4;

Nat8.bitflip(x, p) // Binary : 00011100

Nat8.bitcountNonZero

let bitcountNonZero : (x : Nat8) -> Nat8

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 12; // Binary : 00001100

Nat8.bitcountNonZero(x)

Nat8.bitcountLeadingZero

let bitcountLeadingZero : (x : Nat8) -> Nat8

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 12; // Binary : 00001100

Nat8.bitcountLeadingZero(x)

Nat8.bitcountTrailingZero

let bitcountTrailingZero : (x : Nat8) -> Nat8

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 12; // Binary : 00001100

Nat8.bitcountTrailingZero(x)

Nat8.addWrap

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 255;
let y : Nat8 = 6;

Nat8.addWrap(x, y)

Nat8.subWrap

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 0;
let y : Nat8 = 1;

Nat8.subWrap(x, y)

Nat8.mulWrap

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 128;
let y : Nat8 = 2;

Nat8.mulWrap(x, y)

Nat8.powWrap

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

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

import Nat8 "mo:base/Nat8";

let x : Nat8 = 4;
let y : Nat8 = 4;

Nat8.powWrap(x, y)