Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let rec write_bits b ~nbits x =
- let x = x land ((1 lsl nbits ) - 1) in (* added *)
- let n = nbits in
- if n + b.nbits >= 32 then begin
- if n > 31 then raise Bits_error;
- let n2 = 32 - b.nbits - 1 in
- let n3 = n - n2 in
- write_bits b ~nbits:n2 (x asr n3);
- write_bits b ~nbits:n3 (x land ((1 lsl n3) - 1));
- end else begin
- (* if n < 0 then raise Bits_error; *)
- (* if (x < 0 || x > (1 lsl n - 1)) && n <> 31 then raise Bits_error; *)
- b.bits <- (b.bits lsl n) lor x;
- b.nbits <- b.nbits + n;
- while b.nbits >= 8 do
- b.nbits <- b.nbits - 8;
- write_byte b.ch (b.bits asr b.nbits)
- done
- end
Advertisement
Add Comment
Please, Sign In to add comment