Verilog 2's Complement Shifter

D

Davy

Hi all,

I am new to Verilog and want to build a 2's Complement Shifter.

I found
%displayb(8'b0001_1000>>2); //Output 0000_0110
%displayb(8'b1001_1000>>2); //Output 0010_0110

So >> is unsigned shift.
How can I build a signed (2's Complement) shift based on >>?
i.e. I want 8'b1001_1000>>2 //Output 1110_0110

Any suggestions will be appreciated!
Best regards,
Davy
 
S

Spehro Pefhany

Hi all,

I am new to Verilog and want to build a 2's Complement Shifter.

I found
%displayb(8'b0001_1000>>2); //Output 0000_0110
%displayb(8'b1001_1000>>2); //Output 0010_0110

So >> is unsigned shift.
How can I build a signed (2's Complement) shift based on >>?
i.e. I want 8'b1001_1000>>2 //Output 1110_0110

Any suggestions will be appreciated!
Best regards,
Davy

Verilog 2001 has >>> (signed shift operator)


Best regards,
Spehro Pefhany
 
A

Alan Nishioka

Davy said:
How can I build a signed (2's Complement) shift based on >>?
i.e. I want 8'b1001_1000>>2 //Output 1110_0110

How about
12'b1111_1001_1000>>2
or
{ 32{b[7]}, b } >> 2
 
S

sharp

But note that the so-called "signed shift" only gives you a signed or
arithmetic shift if it is used in a signed expression. In an unsigned
expression, you get an unsigned or logical shift. It isn't really a
"signed shift". It is a "shift using the signedness of the
expression". It is what the ordinary shift operator should have been
in the first place.
 

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,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top