Thread: use of ~

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    3

    use of ~

    hi,
    can any one explain whats use of ~?
    ( for example a=5; s=~a;
    if i print the value of s it becomes -6 why its happen like this?)

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    The bitwise operator of negation

    Convert 5 in binary. Switch every bit. What number comes out?
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    3
    thanQ friend.
    iam using integer data type. that's why i got -6.
    Last edited by vigneshmr; 03-03-2013 at 03:23 PM.

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    You figured it out yourself. Nice! But, why don't you explain so that other people can be helped too?

    Well, I think it would be ok, if I did give the explanation here.

    PS - Welcome to the forum
    Last edited by std10093; 03-03-2013 at 03:33 PM.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed