Rust Opis

Opis is an arithmetic library for integer numbers written in Rust.

Usage

In your Cargo.toml:

```

[dependencies] opis = "1.2.0"

```

In your Rust file:

```

use opis::Int;

```

Features

API

Conversion Functions

From Str:

```

let integer1: Int = Int::fromstr("1010101", 2)?;

let integer2: Int = Int::fromstr("674755", 10)?;

let integer3: Int = Int::fromstr("0xABC012", 16)?;

```

To Str:

```

let binarystr: String = integer1.to_str(2);

let decimalstr: String = integer2.to_str(10);

let hexstr: String = integer3.to_str(16);

```

From Bytes:

```

let bytes: Vec = vec![1,2,3,254,255];

let integer4: Int = Int::frombytes(&bytes);

```

To Bytes:

```

let bytes: Vec = integer4.tobytes();

```

Arithmetic Functions

Addition

```

let s = inta.add(&int2b);

```

Subtraction

```

let d = inta.sub(&intb)?;

```

Multiplication

```

let p = inta.mul(&intb);

```

Division

```

let q = inta.div(&intb)?;

```

Remainder

```

let r = inta.rem(&intb)?;

```

Modulo

```

let m = inta.modulo(&intb)?;

```

Exponentiation

```

let p = inta.pow(&inte);

```

Modular Inverse

```

let mi = inta.modinv(&int_m);

```

Comparison Functions

```

let ans1: bool = inta.isgreater(&intb);

let ans2: bool = inta.isless(&intb);

let ans3: bool = inta.isequal(&intb);

```

Bitwise Functions

NOT

```

let n = int_x.not();

```

AND

```

let a = intx.and(&inty);

```

OR

```

let o = intx.or(&inty);

```

XOR

```

let x = intx.xor(&inty);

```

Future

Contribution

Pull requests, bug reports and any kind of suggestion are welcome.

2021-12-22