Automatically exported from code.google.com/p/jinahya
jinahya / bit-io Goto Github PK
View Code? Open in Web Editor NEWA library for reading/writing arbitrary length of bits.
License: Apache License 2.0
A library for reading/writing arbitrary length of bits.
License: Apache License 2.0
Re:
There are a few places in the code base that use integer division and modular arithmetic. It may be possible to replace them with faster bit-shifting equivalents. Imagine a variable mPosition
that points to a particular bit within a byte array. Retrieving the value of the bit can be accomplished as follows, where BYTE_INDEX_SHIFT
equals 3
(i.e., log base 2 of 8):
final int byteIndex = (int) (mPosition >> BYTE_INDEX_SHIFT);
final int bitIndex = (int) (mPosition - (byteIndex << BYTE_INDEX_SHIFT));
final int bitShifts = Byte.SIZE - bitIndex - 1;
final int bit = (mSequence[byteIndex] & (1 << bitShifts)) >> bitShifts;
I suspect such calculations will be more efficient than using %
, especially on older hardware.
Consider adding a method that skips ahead by n bits, such as:
final byte[] bytes = { 0b01011001, 0b01100101 };
final ArrayByteInput byteInput = new ArrayByteInput( bytes );
final BitInput bitInput = new DefaultBitInput( byteInput );
bitInput.skip( 5 );
final int i = bitInput.readInt( true, 6 );
final boolean bo = bitInput.readBoolean();
final byte nibble = bitInput.readByte( true, 4 ); // Or bitInput.readNybble();?
Great stuff, but sadly I do now miss the "flush()" that basically writes through to byte buffer without advancing the position. As I do have a concurrent read on the ByteBuffer I need all Bits also in the last octet filled (padded with 0)
I don't want to call align(8) after every write as my data consumes only 2 bits in many cases.
Consider a convenience method that reads 4 bits into a byte:
final BitInput bitInput = new DefaultBitInput( ... );
final byte nybble = bitInput.readNybble();
Make AbstractBitInput#octet
and AbstractBitOutput#octet
private
Hi - nice library.
The docs show ByteInput being used with various methods like readBoolean or ints but v2.0.2 ByteInput only has a single read int method. Can you point me to the correct implementation to read bits from a byte array?
I can help with your readme once i get it working
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.