Like Tree1Likes
  • 1 Post By std10093

use of ~

This is a discussion on use of ~ within the C Programming forums, part of the General Programming Boards category; hi, can any one explain whats use of ~? ( for example a=5; s=~a; if i print the value 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,681
    The bitwise operator of negation

    Convert 5 in binary. Switch every bit. What number comes out?
    vigneshmr likes this.
    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 02:23 PM.

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    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 02: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21