bitwise not operator

Discussion in 'C Programming' started by Mantorok Redgormor, Oct 1, 2003.

  1. Should I avoid its use? It seems its use from alot of other posts that
    I have read is discouraged because a discussion always begins on how
    implementation defined behavior occurs with it.

    ~0 [ this is not well defined right? ]
    [ if anyone ever used this in code it would not be portable? ]

    ~-1 [ well defined? ]

    ~25 [ well defined? ]

    etc..
    Mantorok Redgormor, Oct 1, 2003
    #1
    1. Advertising

  2. Mantorok Redgormor

    Dan Pop Guest

    In <> (Mantorok Redgormor) writes:

    >Should I avoid its use? It seems its use from alot of other posts that
    >I have read is discouraged because a discussion always begins on how
    >implementation defined behavior occurs with it.
    >
    >~0 [ this is not well defined right? ]
    > [ if anyone ever used this in code it would not be portable? ]
    >
    >~-1 [ well defined? ]
    >
    >~25 [ well defined? ]


    It is well defined on unsigned operands only. The result on signed
    operands is implementation-defined, because the standard allows more than
    one representation for negative values. Furthermore, depending on the C99
    implementation, applying it to certain signed values may result in trap
    representations (e.g. ~INT_MAX for two's complement and sign-magnitude
    and ~0 for one's complement).

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Oct 1, 2003
    #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. littlehobo

    Bitwise operator question...

    littlehobo, Sep 30, 2003, in forum: C++
    Replies:
    10
    Views:
    6,027
    Ron Natalie
    Oct 1, 2003
  2. Manish_Ganvir
    Replies:
    13
    Views:
    1,559
    Keith Thompson
    Feb 14, 2005
  3. Ioannis Vranos
    Replies:
    8
    Views:
    327
    James Kanze
    Nov 14, 2008
  4. Matt Kruse

    Bitwise NOT operator ( ~ )

    Matt Kruse, May 12, 2009, in forum: Javascript
    Replies:
    3
    Views:
    109
    Dr J R Stockton
    May 16, 2009
  5. aleksa

    Bitwise Not Operator

    aleksa, Jun 26, 2012, in forum: C Programming
    Replies:
    5
    Views:
    500
    James Kuyper
    Jun 26, 2012
Loading...

Share This Page