Verilog 2's Complement Shifter

Discussion in 'VHDL' started by Davy, Feb 7, 2006.

  1. Davy

    Davy Guest

    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
    Davy, Feb 7, 2006
    #1
    1. Advertising

  2. On 6 Feb 2006 22:14:32 -0800, the renowned "Davy"
    <> wrote:

    >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
    --
    "it's the network..." "The Journey is the reward"
    Info for manufacturers: http://www.trexon.com
    Embedded software/hardware/analog Info for designers: http://www.speff.com
    Spehro Pefhany, Feb 7, 2006
    #2
    1. Advertising

  3. Davy wrote:
    > 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
    Alan Nishioka, Feb 7, 2006
    #3
  4. Davy

    Guest

    WHY do Verilog users post in this newsgroup ?

    Rgds
    Andrés
    , Feb 7, 2006
    #4
  5. Davy

    Guest

    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.
    , Feb 7, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fano
    Replies:
    9
    Views:
    2,222
    Ray Andraka
    Oct 16, 2003
  2. Mantorok Redgormor

    sign magnitude, ones complement, two's complement

    Mantorok Redgormor, Oct 5, 2003, in forum: C Programming
    Replies:
    8
    Views:
    8,588
    Glen Herrmannsfeldt
    Oct 8, 2003
  3. sarathy

    1's complement and 2's complement

    sarathy, Aug 1, 2006, in forum: C Programming
    Replies:
    20
    Views:
    2,186
    Bo Persson
    Aug 2, 2006
  4. sarathy
    Replies:
    22
    Views:
    2,340
    Bo Persson
    Aug 2, 2006
  5. Roberto Waltman

    2's complement vs. 1's complement vs. ...

    Roberto Waltman, Jun 9, 2011, in forum: C Programming
    Replies:
    4
    Views:
    1,349
    Michael Press
    Jun 14, 2011
Loading...

Share This Page