c++ - extracting a byte from memory by bit address -


I am working with data in which there are many odd quantities of bits in its values ​​(like 3 bit or 71, you Imagine what you can do), all tightly sorted together. To remove the data, I thought I would first create a function that would retrieve a byte through the bit address and then I can tie them together for more than 8 bits.

Now I am very confused, what I am doing:

  Unsigned four data [=] {0, 255, 2, 255, 4, 5, 6 , 7}; UInt64 biton = 64; // test data UInt64 byteleen = bitton% 8 == 0? Bitolon / 8: bit lane / 8 + 1; ... unsigned char gateUse (UInt64 bitmdx) {UInt64 bioteidx = BITIDX / 8; UInt16 bulk = byteleen - 1 == bytexx? Data [byteidx]: * (UInt16 *) and data [byteidx]; Return Bulk & gt; & Gt; (8- (BITIDX - Byte IDx))% 8; }  

The idea is that if the bittext containing a byte in the dataset is last, then get the value as the value, otherwise in the form of UInt16 (which should be received byte and the next one ). Then

Bitoffet = BITIDX - Byte IDX * 8

8 - Bitoffset = how much padding from left

and finally 8% so that alliance with BITIDX byte idex, Then zodiac = 0.

And then I move it to the right and return fewer order bits.

To test, I used binary to use the decimal online to find out that test data in binary

00000111 00000110 00000101 00000100 11111111 00000010 11111111 00000000 00000000

And I used the function to start with bitmadx14, the result was 10111111 while it should be 10000001

For a while I thought bits were going backwards. And then the bytes but nothing else understood Is obtained. Is there an easy way to extract X quantities of bits starting with a bit array from a byte array?

You can call it BitIdx :

  Returns Bulk> gt> & gt; I forgot to subtract the number from eight to  byte idx . ((8 - (BITIDX - 8 * bytexx))% 8);  

Note: computing byteleon can be simplified using a common trick before adding code to N-1 :

  UInt64 byteleen = (BitTill +7) / 8;  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -