Java Iterate Bits in Byte Array

前端 未结 7 1533
夕颜
夕颜 2020-12-08 02:49

How can i iterate bits in a byte array?

相关标签:
7条回答
  • 2020-12-08 03:21

    An alternative would be to use a BitInputStream like the one you can find here and write code like this:

    BitInputStream bin = new BitInputStream(new ByteArrayInputStream(bytes));
        while(true){
            int bit = bin.readBit();
            // do something
        }
    bin.close();
    

    (Note: Code doesn't contain EOFException or IOException handling for brevity.)

    But I'd go with Jon Skeets variant and do it on my own.

    0 讨论(0)
提交回复
热议问题