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. Forcing bits

Forcing bits

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

    What bitwise operator/combination would I use to force a bit...??? Would the following yield the result im looking for..?

    1 & 0 = 1
    1 & 1 = 1

    Basically I wanna ensure the WS_VISIBLE bit is always set. dwStyle & WS_VISIBLE would accomplish this yes...??? Thanx "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

    R M PJ ArendsP 3 Replies Last reply
    0
    • A alex barylski

      What bitwise operator/combination would I use to force a bit...??? Would the following yield the result im looking for..?

      1 & 0 = 1
      1 & 1 = 1

      Basically I wanna ensure the WS_VISIBLE bit is always set. dwStyle & WS_VISIBLE would accomplish this yes...??? Thanx "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      dwStyle |= WS_VISIBLE;

      /ravi Let's put "civil" back into "civilization" http://www.ravib.com ravib@ravib.com

      A 1 Reply Last reply
      0
      • A alex barylski

        What bitwise operator/combination would I use to force a bit...??? Would the following yield the result im looking for..?

        1 & 0 = 1
        1 & 1 = 1

        Basically I wanna ensure the WS_VISIBLE bit is always set. dwStyle & WS_VISIBLE would accomplish this yes...??? Thanx "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

        M Offline
        M Offline
        MSH_ILC
        wrote on last edited by
        #3

        I believe that you use the (dwStyle & WS_VISIBLE) to test if WS_VISIBLE bit is set in dwStyle, which might help you with what you want. However a better way to do this is to use the OR operator ( it's the | : shift+\) the OR operation results in true if any of the arguments was true and false if none were true. ie 1 or 1 = 1 1 or 0 = 1 0 or 1 = 1 0 or 0 = 0 while the AND (&) is only true if both arguments were true. Since WS_VISIBLE is always true, the | operator with dwStyle and WS_VISIBLE will always force the bit you are interested in to true. The usage should be along the lines of: dwStyle= dwStyle | WS_VISIBLE; This will make sure that the flag bit is forced to true while the rest of the bits are unmodified (since WS_VISIBLE has only one bit turned to true). exp: dwStyle 1001110101110111 WS_VISIBLE 0000000010000000 Binary OR (|) 1001110111110111 this is called the Binary OR since it compares bits and results in bits, & is Binary AND too. && and || are the logical operators and compare the arguments bit by bit by return only true or false. Please correct me if I'm wrong, it's been quite a while :) ... -- Young Basic programmers never die... they just GOSUB and never RETURN.

        A 1 Reply Last reply
        0
        • R Ravi Bhavnani

          dwStyle |= WS_VISIBLE;

          /ravi Let's put "civil" back into "civilization" http://www.ravib.com ravib@ravib.com

          A Offline
          A Offline
          alex barylski
          wrote on last edited by
          #4

          Thanx "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

          1 Reply Last reply
          0
          • M MSH_ILC

            I believe that you use the (dwStyle & WS_VISIBLE) to test if WS_VISIBLE bit is set in dwStyle, which might help you with what you want. However a better way to do this is to use the OR operator ( it's the | : shift+\) the OR operation results in true if any of the arguments was true and false if none were true. ie 1 or 1 = 1 1 or 0 = 1 0 or 1 = 1 0 or 0 = 0 while the AND (&) is only true if both arguments were true. Since WS_VISIBLE is always true, the | operator with dwStyle and WS_VISIBLE will always force the bit you are interested in to true. The usage should be along the lines of: dwStyle= dwStyle | WS_VISIBLE; This will make sure that the flag bit is forced to true while the rest of the bits are unmodified (since WS_VISIBLE has only one bit turned to true). exp: dwStyle 1001110101110111 WS_VISIBLE 0000000010000000 Binary OR (|) 1001110111110111 this is called the Binary OR since it compares bits and results in bits, & is Binary AND too. && and || are the logical operators and compare the arguments bit by bit by return only true or false. Please correct me if I'm wrong, it's been quite a while :) ... -- Young Basic programmers never die... they just GOSUB and never RETURN.

            A Offline
            A Offline
            alex barylski
            wrote on last edited by
            #5

            Thanx "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

            1 Reply Last reply
            0
            • A alex barylski

              What bitwise operator/combination would I use to force a bit...??? Would the following yield the result im looking for..?

              1 & 0 = 1
              1 & 1 = 1

              Basically I wanna ensure the WS_VISIBLE bit is always set. dwStyle & WS_VISIBLE would accomplish this yes...??? Thanx "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

              PJ ArendsP Offline
              PJ ArendsP Offline
              PJ Arends
              wrote on last edited by
              #6

              http://www.codeproject.com/cpp/bitbashing.asp


              CPUA 0x5041 Sonork 100.11743 Chicken Little "So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies Within you lies the power for good - Use it!

              Within you lies the power for good; Use it!

              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