shift - helpneeded with codeexplanation

Status
Not open for further replies.

jasonkee111

Junior Member level 3
Joined
Feb 8, 2009
Messages
28
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,501
shift

can somebody explain the code below

input wire signed [16:0] D,
output reg signed [16:0] Q );

always @ * begin
Q = D;
for(j=0;j<i;j=j+1)
Q = (Q >> 1) | (D[16] << 16);

Question:
1. What is the meaning D[`16] << 16? from i understand, it shift left 16 times of D whereby D only 1 bit due to D[16]. Am i misunderstand?

2. why it use Q and D in the statement "Q = (Q >> 1) | (D[16] << 16);" since D is assigned to Q?

Thanks
 

Re: shift

I am not completely sure as to why this happens but it looks like (D[16] << 16) takes your sign bit and and assigns it to Q[16] . Since both your variables are signed, when Q is shifted by one, the MSB bit is maintained by 'ORing' it with (Q>>1). I'd be interested to know details about this if you find out more!
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…