What is the most efficient way in Java to pack bits into byte[] and read it back?

前端 未结 1 1368
[愿得一人]
[愿得一人] 2021-02-08 02:33

I currently use these two functions to pack and read bits in a byte array. Wondering if anybody has any better ideas or faster ways to do it?

Edited the program with a

1条回答
  •  既然无缘
    2021-02-08 02:34

    A totally different route would be to define static table of all possible combinations and perform a lookup instead of calculating results each time. I think thats how they do it in cryptography. array[i] x 3 should be much faster than numBits bitwise operations. It will occupy some heap though.

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