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. Article Writing
  3. How can I read individual bit values in a returned integer

How can I read individual bit values in a returned integer

Scheduled Pinned Locked Moved Article Writing
3 Posts 3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I am calling an API function that returns an Integer. MSDN documentation states 'The only valid bits in the return value are those that correspond to the bits set in the mask parameter' How do I read these individual bit values. Regards, SAK:)

    P J 2 Replies Last reply
    0
    • L Lost User

      I am calling an API function that returns an Integer. MSDN documentation states 'The only valid bits in the return value are those that correspond to the bits set in the mask parameter' How do I read these individual bit values. Regards, SAK:)

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      The API documentation probably has a list of values that can be ORed together to make the mask that you pass in as the mask parameter. To check if a bit is set, take the return value and AND it with the bit value you want. ie

      int ret = APIFunc(MASK1 | MASK2);
      if (ret & MASK1)
      {
      // MASK1 bit is set;
      }
      etc.

      --- The Center for Disease Control in Atlanta announced that Clinton has proven that you can get sex from Aides.

      1 Reply Last reply
      0
      • L Lost User

        I am calling an API function that returns an Integer. MSDN documentation states 'The only valid bits in the return value are those that correspond to the bits set in the mask parameter' How do I read these individual bit values. Regards, SAK:)

        J Offline
        J Offline
        Jim Crafton
        wrote on last edited by
        #3

        An alternate solution that I have found useful when having to check a specific bit, like checking whether bit 29 in a 32 bit value is on or off, is using the std::bitset class. std::bitset<32> keyBits; if ( keyBits[29] == 1 ) { //bit 29 is set //do something }

        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