public final int decodeUnsignedInteger ( ) throws IOException { // 0XXXXXXX ... 1XXXXXXX 1XXXXXXX int result = decode ( ) ; // < 128: just one byte, optimal case // ELSE: multiple bytes... if ( result >= 128 ) { result = ( result & 127 ) ; int mShift = 7 ; int b ; do { // 1. Read the next octet b = decode ( ) ; // 2. Multiply the value of the unsigned number represented by // the 7 least significant // bits of the octet by the current multiplier and add the // result to the current value. result += ( b & 127 ) << mShift ; // 3. Multiply the multiplier by 128 mShift += 7 ; // 4. If the most significant bit of the octet was 1, go back to // step 1 } while ( b >= 128 ) ; } return result ; }
Decode an arbitrary precision non negative integer using a sequence of octets . The most significant bit of the last octet is set to zero to indicate sequence termination . Only seven bits per octet are used to store the integer s value .