machine dependent left shift results

Discussion in 'Perl' started by easily_confused, Oct 1, 2009.

  1. On a 32 bit machine, ~0<<32 gives 11111111111111111111111111111111 (I was
    expecting 0)

    (~0<<31)<<1 gives 0.

    I was trying ~(~0<<$size) to create a mask of $size ones.

    ((1<<$size) -1) was what I tried first but it also failed for the same
    reason, I guess.

    I like that in verilog I can just say {$size{1'b1}}

    I know I can use Math::BigInt, but I still wonder what the rationale is
    behind the first example failing.

    EC
     
    easily_confused, Oct 1, 2009
    #1
    1. Advertising

  2. reposted on comp.lang.perl.misc
    please respond there


    "easily_confused" <> wrote in message
    news:003ff6be$0$32523$...
    > On a 32 bit machine, ~0<<32 gives 11111111111111111111111111111111 (I was
    > expecting 0)
    >
    > (~0<<31)<<1 gives 0.
    >
    > I was trying ~(~0<<$size) to create a mask of $size ones.
    >
    > ((1<<$size) -1) was what I tried first but it also failed for the same
    > reason, I guess.
    >
    > I like that in verilog I can just say {$size{1'b1}}
    >
    > I know I can use Math::BigInt, but I still wonder what the rationale is
    > behind the first example failing.
    >
    > EC
    >
    >
    >
     
    easily_confused, Oct 1, 2009
    #2
    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. Wenjie
    Replies:
    3
    Views:
    1,094
    Ron Samuel Klatchko
    Jul 11, 2003
  2. Santosh Nayak

    Left Shift / Right Shift Operators

    Santosh Nayak, Nov 30, 2006, in forum: C Programming
    Replies:
    16
    Views:
    1,506
    CBFalconer
    Nov 30, 2006
  3. Sanny
    Replies:
    38
    Views:
    3,573
    Thomas Richter
    Apr 29, 2011
  4. pc
    Replies:
    2
    Views:
    1,393
    crisgoogle
    Jun 8, 2011
  5. easily_confused

    machine dependent left shift results

    easily_confused, Oct 1, 2009, in forum: Perl Misc
    Replies:
    2
    Views:
    252
    Peter J. Holzer
    Oct 2, 2009
Loading...

Share This Page