Function bech32::convert_bits[][src]

pub fn convert_bits<T>(
    data: &[T],
    from: u32,
    to: u32,
    pad: bool
) -> Result<Vec<u8>, Error> where
    T: Into<u8> + Copy

Convert between bit sizes

Errors

  • Error::InvalidData if any element of data is out of range
  • Error::InvalidPadding if pad == false and the padding bits are not 0

Panics

Function will panic if attempting to convert from or to a bit size that is 0 or larger than 8 bits.

Examples

use bech32::convert_bits;
let base5 = convert_bits(&[0xff], 8, 5, true);
assert_eq!(base5.unwrap(), vec![0x1f, 0x1c]);