Opis is an arithmetic library for integer numbers written in Rust.
In your Cargo.toml
:
```
[dependencies] opis = "1.2.0"
```
In your Rust file:
```
use opis::Int;
```
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
let integer4: Int = Int::frombytes(&bytes);
```
To Bytes
:
```
let bytes: Vec
```
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);
```
```
let ans1: bool = inta.isgreater(&intb);
let ans2: bool = inta.isless(&intb);
let ans3: bool = inta.isequal(&intb);
```
NOT
```
let n = int_x.not();
```
AND
```
let a = intx.and(&inty);
```
OR
```
let o = intx.or(&inty);
```
XOR
```
let x = intx.xor(&inty);
```
Pull requests, bug reports and any kind of suggestion are welcome.
2021-12-22