pub fn shift_left(buffer: &[u8], shift: isize) -> Vec<u8> {
    if shift < 0 {
        return shift_right(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();
    let mut new_buffer = vec![0; length];

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

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