pub fn shift_right(buffer: &[u8], shift: isize) -> Vec<u8> {
    if shift < 0 {
        return shift_left(buffer, -shift);
    }

    let modulate: usize = shift as usize % BYTE;

    if modulate == 0 {
        return buffer.to_vec();
    }

    let mask: u8 = 0xFF >> (BYTE - modulate);
    let length = buffer.len() + 1;
    let mut new_buffer = vec![0; length];

    for i in (1..length).rev() {
        let b = &buffer[i - 1];
        new_buffer[i] |= (0xFF & b & mask) << (BYTE - modulate);
        new_buffer[i - 1] = (0xFF & b) >> modulate;
    }

    new_buffer
}
/**
 * Shifts bits in a byte array to the right modulo 8
 */
Shifts bits in a byte array to the right modulo 8
Shifts bits in a byte array to the right modulo 8
pub fn shift_right(buffer: &[u8], shift: isize) -> Vec<u8> {
    if shift < 0 {
        return shift_left(buffer, -shift);
    }
    let modulate: usize = shift as usize % BYTE;
    if modulate == 0 {
        return buffer.to_vec();
    }
    let mask: u8 = 0xFF >> (BYTE - modulate);
    let length = buffer.len() + 1;
    let mut new_buffer = vec![0; length];
    for i in (1..length).rev() {
        let b = &buffer[i - 1];
        new_buffer[i] |= (0xFF & b & mask) << (BYTE - modulate);
        new_buffer[i - 1] = (0xFF & b) >> modulate;
    }
    new_buffer
}
pub fn shift_right ( buffer : & [ u8 ] , shift : isize ) -> Vec < u8 > { if shift < 0 { return shift_left ( buffer , - shift ) ; } let modulate : usize = shift as usize % BYTE ; if modulate == 0 { return buffer . to_vec ( ) ; } let mask : u8 = 0xFF >> ( BYTE - modulate ) ; let length = buffer . len ( ) + 1 ; let mut new_buffer = vec ! [ 0 length ] ; for i in ( 1 .. length ) . rev ( ) { let b = & buffer [ i - 1 ] ; new_buffer [ i ] |= ( 0xFF & b & mask ) << ( BYTE - modulate ) ; new_buffer [ i - 1 ] = ( 0xFF & b ) >> modulate ; } new_buffer }
Shifts bits in a byte array to the right modulo 8
Shifts bits in a byte array to the right modulo 8
buffer
&[u8]
shift
isize
buffer
&[u8]
shift
isize