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. Bitwise Left Shift

Bitwise Left Shift

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 5 Posters 3 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.
  • A Offline
    A Offline
    Anthony9887
    wrote on last edited by
    #1

    I noticed that whenever I use the "<<" bitwise left shift operator. The result value is incorrect. The bitwise right shift is correct. Whats up with this? Any ideas? ie 49<<3 should be 136, but I get 392. Thanks

    M A D 3 Replies Last reply
    0
    • A Anthony9887

      I noticed that whenever I use the "<<" bitwise left shift operator. The result value is incorrect. The bitwise right shift is correct. Whats up with this? Any ideas? ie 49<<3 should be 136, but I get 392. Thanks

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      49*8 is 392. How are you calculating 136? --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- You cannot stop me with paramecium alone!

      A 1 Reply Last reply
      0
      • A Anthony9887

        I noticed that whenever I use the "<<" bitwise left shift operator. The result value is incorrect. The bitwise right shift is correct. Whats up with this? Any ideas? ie 49<<3 should be 136, but I get 392. Thanks

        A Offline
        A Offline
        Antony M Kancidrowski
        wrote on last edited by
        #3

        I see what you have done. You need to AND with 255 to get the answer. Ant.

        1 Reply Last reply
        0
        • M Michael Dunn

          49*8 is 392. How are you calculating 136? --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- You cannot stop me with paramecium alone!

          A Offline
          A Offline
          Antony M Kancidrowski
          wrote on last edited by
          #4

          I assume he is taking it as 8bits and therefore the top bit falls off the end! ;) Ant.

          M 1 Reply Last reply
          0
          • A Anthony9887

            I noticed that whenever I use the "<<" bitwise left shift operator. The result value is incorrect. The bitwise right shift is correct. Whats up with this? Any ideas? ie 49<<3 should be 136, but I get 392. Thanks

            D Offline
            D Offline
            deniz79s
            wrote on last edited by
            #5

            one time right shift is like divide with 2 and one time left shift is like multiple wiht 2. So How can you find 136 result

            1 Reply Last reply
            0
            • A Antony M Kancidrowski

              I assume he is taking it as 8bits and therefore the top bit falls off the end! ;) Ant.

              M Offline
              M Offline
              mirex
              wrote on last edited by
              #6

              Then you should be shifting an 8bit variable, like 'unsigned char'. You are probably shifting 'int' or something. Or cut it to 8 bits with AND 255

              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