![]() ![]() Throw new ArgumentOutOfRangeException( "data", data, "must be between min and max" ) Public void Write( byte data, byte min, byte max ) / the maximum number that can be written / the minimum number that can be written Write( BitConverter.GetBytes( data ), 1 ) Scratch_write |= ( ( data > scratch_write_bits ) Protected void Write( ulong data, int bits ) Result = (byte) ( scratch > ( 64 - bitsToStore ) ) īitArray ba = new BitArray( buffer.Count * 64 + scratch_write_bits ) Int extraBytes = (int) IntDivideRoundUp( scratch_write_bits, 8 ) īyte result = new byte īuffer.BlockCopy( buffer.ToArray(), 0, result, 0, result.Length - extraBytes ) / Get the bits stored in a byte array (left-endian) Ulong result = new ulong Īrray.Copy( buffer.ToArray(), result, buffer.Count ) / Get the bits stored in a ulong array (left-endian) Write( bite, byte.MinValue, byte.MaxValue ) / contains bits to be stored in the bitstream / NOTE: StoredBits may return a higher count than there are actual bits to read if the byte array came from another BitStream. / Make a new BitStream containing bits from the byte array A closer value nets increased performance.īuffer = new Queue( (int) IntDivideRoundUp( bitCount, 64 ) ) ![]() / How many bits you expect this stream will hold. / How many bits are currently in the BitStream / Reading from an empty BitStream returns 0. If read in a different order, it gives undefined results. / Data should be read in the same order it is written. Acts as a queue - first data added is the first data removed. How can I improve it? Any way to make it more efficient? How can I reduce the amount of code? I have a lot of copy/pasted code with minor things changed that I'm not sure how (if?) I can condense.Īnd, of course, any other comments. Would it benefit from being named BitPacker rather than BitStream (and change write/read to pack/unpack), or it works as is? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |