def to_unsigned(number, nb_bits):
    """Compute the unsigned value of the given number according to the given number of bits used for encoding.

    >>> to_unsigned(5, 32)
    5
    >>> to_unsigned(-5, 8)
    251
    >>> to_unsigned(-5, 9)
    507

    :param int number: the number to convert.
    :param int nb_bits: the number of bits considered.

    :returns: an integer which is the unsigned value of the given number.

    """
    if number < 0:
        return (1 << nb_bits) + number

    return number