开发者

How Byte data be converted to bits and again converted back to Byte?

1 Byte = 8 bits. I have to work on 120 bits. So 15 Byte. This 120 bits will be in the form of 00010101000000............ So each 8 bit t开发者_如何学JAVAhat is 00010101 is 1 Byte. So I want do some kind of modification operation on that and then add up all the Bytes back. Will the Bytes be stored in an Byte array?


If you have a large number of bits you could use BitSet. You can use byte[] or long[] it doesn't matter as they are all made up of bits in the end. Using a byte[] won't make the object any smaller than a long[] as most JVMs use 8-byte boundaries for objects. A long[] is more efficent for some operations.


Byte array is a good idea. But it is up to you how to store them...


Split the stream in 8 bit chunks and use Byte.valueOf(String, int) for each chunk.


It is up to you how you will store the bytes. You can modify bytes using bits operations like & and |. For ex.:

x |= 2;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜