All pastes #627592 Raw Edit

Anonym

public text v1 · immutable
·published 2007-07-20 12:43 UTC
rendered paste body
	function readBits ( n : Int ) : Int {
		if( byte == null ) {
			remaining = 0;
		}
		
		var bits = 0;
		while( n > 0 ) {
			if( remaining == 0 ) {
				remaining = 8;
				byte = readUI8();
			}
			var len = Math.round( Math.min( remaining, n ) );
			bits = (bits << len) | ((byte >> (remaining - len)) & (-1 >> (32 - len)));
			n -= len;
			remaining -= len;
		}
		
		return bits;
	}