Have a problem in finding the output of an program.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AnagJohari
    New Member
    • May 2010
    • 96

    Have a problem in finding the output of an program.

    Code:
    int main()
    {
        unsigned int m = 32;
        printf("%x\n", ~m);
        return 0;
    }
    where int is 32 bits
    can u explain how the 32 stored in a memory
    according to me:-
    -------------------
    binary no-100000
    here is only 6 bit
    can u explain the representation of "32" in 32 bits form in a memory

    by the way the ans of this :-ffdf

    please explain why this ans comes
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    In 6 bit 32 looks like 100000
    In 32 bit it looks like (0)000000000000 000000000000010 0000

    Where 0 within the ( ) indicates the sign bit.

    And output must be
    Code:
    ffffffdf
    ~ operator does the bitwise complement(1's complement). i.e all the bits in an expression will be flipped.

    Regards
    Dheeraj Joshi

    Comment

    • AnagJohari
      New Member
      • May 2010
      • 96

      #3
      Originally posted by dheerajjoshim
      In 6 bit 32 looks like 100000
      In 32 bit it looks like (0)000000000000 000000000000010 0000

      Where 0 within the ( ) indicates the sign bit.

      And output must be
      Code:
      ffffffdf
      ~ operator does the bitwise complement(1's complement). i.e all the bits in an expression will be flipped.

      Regards
      Dheeraj Joshi
      can u reply in stepwise way how this ans comes..

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        You should familiarize yourself with the bitwise operators. (Notice that the referenced article is about the operators, not how to express them in any particular computer language.)

        You should familiarize yourself with two's-complement representation of binary numbers. The C Standard does not mandate two's-complement representation, but that is by far the most common representation. It is clear from the "correct answer" that your machine uses two's-complement.

        Comment

        Working...