Hi,

Can anyone help me read the code below? I have an idea but i am not quite sure.

*(DWORD*)(pDesPtr+(nDesIndex>>3)) |=  pSrc[nCount] << (nDesIndex&7);

thanks a lot,

Hi,

Can anyone help me read the code below? I have an idea but i am not quite sure.

*(DWORD*)(pDesPtr+(nDesIndex>>3)) |=  pSrc[nCount] << (nDesIndex&7);

thanks a lot,

I take it that it's the left hand size which is puzzling you.

nDesIndex >> 3
Shift the value in nDesIndex right 3 places. Judging by the right hand side another index is stored in the first three bits on nDesIndex, so the programmer is getting them out of the way.

pDesPtr + ( nDesIndex >> 3 )
Having got the index in the msbits of nDesIndex into the lsbits, add that index onto pDesPtr. (Getting you a new pointer nDesIndex places on from pDesPtr.

(DWORD*)( pDesPtr + (nDesIndex >> 3))
Treat the pointer as a pointer to a 32 bit value (byte = 8 bits, word = 16 bits, dword = 32 bits)

*(DWORD)(pDesPtr + (nDesIndex >> 3))
Actually gets you that 32 bit value.

The value on the RH side is then being ORed into it.

> I have an idea but i am not quite sure.
So explain your reasoning, and then we can tell if you're on the right track.

At the risk of sounding as if I have got a big head, I'm sure I'm right. I suppose have been writing C programs since about 1987, and usually they are between 20 and 30 thousand lines long. But I hate to make a fool of myself, so I have double and triple checked what I wrote above.

My reasoning is as above. In the syntax of C |= OR's the right hand operand into the left hand operand.

At the risk of sounding as if I have got a big head, I'm sure I'm right. I suppose have been writing C programs since about 1987, and usually they are between 20 and 30 thousand lines long. But I hate to make a fool of myself, so I have double and triple checked what I wrote above.

My reasoning is as above. In the syntax of C |= OR's the right hand operand into the left hand operand.

Hehe looks like you misunderstood. Mr. Salem said the above statement to the OP and not to you. So just chill since the sarcasm wasnt intended for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.