pub trait ArrayBinary<N: Numeric>where
    Self: Sized + Clone,{
    // Required methods
    fn bitwise_and(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>;
    fn bitwise_or(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>;
    fn bitwise_xor(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>;
    fn bitwise_not(&self) -> Result<Array<N>, ArrayError>;
    fn invert(&self) -> Result<Array<N>, ArrayError>;
    fn left_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>;
    fn right_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>;
    fn binary_repr(num: N) -> String;
}
Expand description

ArrayTrait - Binary Array operations

Required Methods§

source

fn bitwise_and(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Compute the bit-wise AND of two arrays element-wise

Arguments
  • other - array to perform the operation with
Examples
use arr_rs::prelude::*;

assert_eq!(Array::<i32>::flat(vec![1]), array!(i32, [13]).bitwise_and(&array!(i32, [17]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![0, 1]), array!(i32, [11, 7]).bitwise_and(&array!(i32, [4, 25]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![2, 4, 16]), array!(i32, [2, 5, 255]).bitwise_and(&array!(i32, [3, 14, 16]).unwrap()));
source

fn bitwise_or(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Compute the bit-wise OR of two arrays element-wise

Arguments
  • other - array to perform the operation with
Examples
use arr_rs::prelude::*;

assert_eq!(Array::<i32>::flat(vec![29]), array!(i32, [13]).bitwise_or(&array!(i32, [16]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![33, 6]), array!(i32, [33, 4]).bitwise_or(&array!(i32, [1, 2]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![6, 5, 255]), array!(i32, [2, 5, 255]).bitwise_or(&array!(i32, [4, 4, 4]).unwrap()));
source

fn bitwise_xor(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Compute the bit-wise XOR of two arrays element-wise

Arguments
  • other - array to perform the operation with
Examples
use arr_rs::prelude::*;

assert_eq!(Array::<i32>::flat(vec![28]), array!(i32, [13]).bitwise_xor(&array!(i32, [17]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![26]), array!(i32, [31]).bitwise_xor(&array!(i32, [5]).unwrap()));
assert_eq!(Array::<i32>::flat(vec![26, 5]), array!(i32, [31, 3]).bitwise_xor(&array!(i32, [5, 6]).unwrap()));
source

fn bitwise_not(&self) -> Result<Array<N>, ArrayError>

Compute bit-wise inversion, or bit-wise NOT, element-wise

Arguments
  • other - array to perform the operation with
Examples
use arr_rs::prelude::*;

assert_eq!(Array::<u8>::flat(vec![242]), array!(u8, [13]).bitwise_not());
assert_eq!(Array::<u16>::flat(vec![65522]), array!(u16, [13]).bitwise_not());
assert_eq!(Array::<i32>::flat(vec![-14]), array!(i32, [13]).bitwise_not());
source

fn invert(&self) -> Result<Array<N>, ArrayError>

Compute bit-wise inversion, or bit-wise NOT, element-wise. Alias on bitwise_not

Arguments
  • other - array to perform the operation with
Examples
use arr_rs::prelude::*;

assert_eq!(Array::<u8>::flat(vec![242]), array!(u8, [13]).invert());
assert_eq!(Array::<u16>::flat(vec![65522]), array!(u16, [13]).invert());
assert_eq!(Array::<i32>::flat(vec![-14]), array!(i32, [13]).invert());
source

fn left_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Shift the bits of an integer to the left

Arguments
  • other - array to perform the operation with
Examples
use arr_rs::prelude::*;

assert_eq!(Array::<u8>::flat(vec![20]), array!(u8, [5]).left_shift(&array!(u8, [2]).unwrap()));
assert_eq!(Array::<u8>::flat(vec![10, 20, 40]), array!(u8, [5]).left_shift(&array!(u8, [1, 2, 3]).unwrap()));
source

fn right_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

Shift the bits of an integer to the right

Arguments
  • other - array to perform the operation with
Examples
use arr_rs::prelude::*;

assert_eq!(Array::<u8>::flat(vec![5]), array!(u8, [10]).right_shift(&array!(u8, [1]).unwrap()));
assert_eq!(Array::<u8>::flat(vec![5, 2, 1]), array!(u8, [10]).right_shift(&array!(u8, [1, 2, 3]).unwrap()));
source

fn binary_repr(num: N) -> String

Return the binary representation of the input number as a string

Arguments
  • num - integer decimal number
Examples
use arr_rs::prelude::*;

assert_eq!("10".to_string(), 2u8.binary_repr());
assert_eq!("11".to_string(), 3u8.binary_repr());
assert_eq!("11111101".to_string(), (-3i8).binary_repr());
assert_eq!("11111111".to_string(), 255u8.binary_repr());

assert_eq!("10".to_string(), Array::<u8>::binary_repr(2));
assert_eq!("11".to_string(), Array::<u8>::binary_repr(3));
assert_eq!("11111101".to_string(), Array::<i8>::binary_repr(-3));
assert_eq!("11111111".to_string(), Array::<u8>::binary_repr(255));

Implementations on Foreign Types§

source§

impl<N: Numeric> ArrayBinary<N> for Result<Array<N>, ArrayError>

source§

fn bitwise_and(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn bitwise_or(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn bitwise_xor(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn bitwise_not(&self) -> Result<Array<N>, ArrayError>

source§

fn invert(&self) -> Result<Array<N>, ArrayError>

source§

fn left_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn right_shift(&self, other: &Array<N>) -> Result<Array<N>, ArrayError>

source§

fn binary_repr(num: N) -> String

Implementors§

source§

impl<N: Numeric> ArrayBinary<N> for Array<N>