Simple Rotation and bitmasking problem

P

Patrick

Hi

I have a basic question concerning rotations and bitmasking.

Assume the following code fragement.

uint32 p_lo[] = { 0x00, 0x00};

for (j = 0; j < 64; j++ )

p_lo[0] <<= (j % 32);

p_lo[1] <<= (j % 32);

p_lo[1] |= (p_hi[0] >> (32 - (j % 32)));
}

I itend to do the following. In each iteration shift each element of
the array by an amount of
n. Additionally, the n-bits that are shifted out of each word should
be the least significant bits of the next higher
word. This I try to do by shifting the lower word by 32 - n positions
to the left and OR then the result
with the next higher word. Unfortunately the output does not make
sense.

Has anyone an idea what I am missing?

Many thanks,
Patrick
 
O

Old Wolf

uint32 p_lo[] = { 0x00, 0x00};

for (j = 0; j < 64; j++ )
p_lo[0] <<= (j % 32);
p_lo[1] <<= (j % 32);
p_lo[1] |= (p_hi[0] >> (32 - (j % 32)));
}

I suppose you wanted a '{' after the 'for' statement.
You haven't shown the definition of p_hi. But if it
is an array of 32-bit entities, then you have undefined
behaviour when j==0 and j==32 because you shift its
first element by the entire width of the element.
I itend to do the following. In each iteration shift
each element of the array by an amount of n.
Additionally, the n-bits that are shifted out of each
word should be the least significant bits of the next
higher word.

Don't quite follow the description because you
haven't shown enough code, but in the above
snippets the bits that you shift out of p_lo[0]
and p_lo[1] are all lost.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top