/* Reverses "nbits" bits of the value "val" and returns the result in the least significant bits.  */
static uint16_t inv_bits(uint16_t val, int nbits)
/* Reverses "nbits" bits of the value "val" and returns the result in the least significant bits.  */
static uint16_t inv_bits(uint16_t val, int nbits)
{
    uint16_t res;
    if (nbits <= 8) {
        res = av_reverse[val] >> (8-nbits);
    } else
        res = ((av_reverse[val & 0xFF] << 8) + (av_reverse[val >> 8])) >> (16-nbits);
    return res;
}