Guard against bogus data.

  * When decoding, make sure the resulting number
    is smaller than a 32 bit unsigned int, otherwise
    the data is not valid

  * When encoding, fixes bug where numbers where interpreted
    as signed numbers.