On Jul 11, 7:18 pm, Cindy <luoqing2...@yahoo.comwrote:
I am struggling over a simple way to shift multi bytes for certain
bits. Hope someone can help. For example, I open a memory space for 10
bytes:
unsigned char *pData = new unsigned char[10];
then store some value into pData which occupies pData[8] and pData[9].
Now I want to shift these two bytes to the left for 9 bits and still
store them in pData. The data now should span from the bit0 in
pData[6] to bit1 in pData[8].
Is there a fast way to do it?
No.
Not a fast way, anyway, at least not portably. Basically,
you'll have to do your shifts in a larger type (at least double
the width), separate the parts which go into different bytes,
and then or the results for each byte. You'll also have to pay
attention to not overwrite values you still need if you do it in
place.
--
James Kanze (Gabi Software) email:
ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34