binary

Discussion in 'C' started by gpk kishore, Jul 29, 2011.

  1. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    unsigned int m=32;
    printf("%x",~m);
    }
    sir

    please reply to my posts(I have posted 6 posts for output)
    it's urgent for me

    no one is replying
    why?

    please please
    answer to my threads
     
  2. eriyer

    eriyer New Member

    Joined:
    Jan 22, 2011
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    What is the question / doubt with regard to this program where you are displaying the value in hex after inverting the bits ?
     
  3. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    sir
    printf("%x",~m);
    it will print (~m) value in hexa decimal system

    please explain me the output with explanation
     
  4. srp5789

    srp5789 New Member

    Joined:
    Jul 25, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    output will be ==> ffdf
    its just complement of 0000 0000 0010 0000 or (0020 in hex or 32 in int/unsigned)
    i.e 1111 1111 1101 1111 (ffdf in hex or 65503 in unsigned or -33 in int)
     
  5. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    thank u sir
    but i think
    when we are taking complement we invert all the bits but we will not invert sign bit
    is it crct or not
     
  6. srp5789

    srp5789 New Member

    Joined:
    Jul 25, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    in C 2's complement method is used to represent numbers because of that when you say -1 its not
    1000 0000 0000 0001 but
    1111 1111 1111 1111

    procedure to get this is

    1.write magnitude of original number in binary format i.e. 1 instead of -1

    0000 0000 0000 0001

    2.now invert the bits i.e. (~number)

    1111 1111 1111 1110

    3.now add 1 to step 2

    1111 1111 1111 1111

    here the representation of -1, which is FFFF(1111 1111 1111 1111) and not 8001 (1000 0000 0000 0001).
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice