Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why?

Why?

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _8086
    wrote on last edited by
    #1

    int j; j=4; //100 printf("\n\nj value:%d",(~j));//100-->(NOT)-->011-->So shouldn't this be 2?? It prints -5??? Why?:confused:

    ---------------------------- 286? WOWW!:-O

    J M L 3 Replies Last reply
    0
    • _ _8086

      int j; j=4; //100 printf("\n\nj value:%d",(~j));//100-->(NOT)-->011-->So shouldn't this be 2?? It prints -5??? Why?:confused:

      ---------------------------- 286? WOWW!:-O

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      (4) is hex 0x00000004 ~(4) is hex 0xfffffffb which is a signed integer which is (-5) Jeron

      1 Reply Last reply
      0
      • _ _8086

        int j; j=4; //100 printf("\n\nj value:%d",(~j));//100-->(NOT)-->011-->So shouldn't this be 2?? It prints -5??? Why?:confused:

        ---------------------------- 286? WOWW!:-O

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        _8086 wrote:

        011-->So shouldn't this be 2

        Actually that's 3 :) The ~ operator effects ALL the bits of the integer

        int j; // j is a signed integer - I'll assume 32-bits in length
        j=4; // 00000000000000000000000000000100 (4)
        j=~j; // 11111111111111111111111111111011 (-5)

        "If you can dodge a wrench, you can dodge a ball."

        _ 1 Reply Last reply
        0
        • _ _8086

          int j; j=4; //100 printf("\n\nj value:%d",(~j));//100-->(NOT)-->011-->So shouldn't this be 2?? It prints -5??? Why?:confused:

          ---------------------------- 286? WOWW!:-O

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          :->

          led mike

          1 Reply Last reply
          0
          • M Mark Salsbery

            _8086 wrote:

            011-->So shouldn't this be 2

            Actually that's 3 :) The ~ operator effects ALL the bits of the integer

            int j; // j is a signed integer - I'll assume 32-bits in length
            j=4; // 00000000000000000000000000000100 (4)
            j=~j; // 11111111111111111111111111111011 (-5)

            "If you can dodge a wrench, you can dodge a ball."

            _ Offline
            _ Offline
            _8086
            wrote on last edited by
            #5

            Mark Salsbery wrote:

            Actually that's 3

            :doh: Thanks :)

            ---------------------------- 286? WOWW!:-O

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups