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. Visual Basic
  4. Bitwise Enumeration?

Bitwise Enumeration?

Scheduled Pinned Locked Moved Visual Basic
questioncsharplearning
5 Posts 2 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.
  • W Offline
    W Offline
    watagal
    wrote on last edited by
    #1

    Hi all, Not sure if my subject is correct in describing what I want to do. I have an integer variable (iOptions) where each bit represents an On/Off Flag: 0 = all off 1 = flag1 2 = flag2 4 = flag3 8 = flag4 ....... and so on Of course this integer variable could equal to 7 (flag1+flag2+flag3 are On) or anywhere in between. How do I write a bitwise if statement to check if anyone flag is On? if iFlag1 ?? iOptions then ' **What goes here instead of ??** ... else if iFlag2 ?? iOptions then ... end if Thanks, Karen Nooobie to OOP and VB.Net 2005

    B 1 Reply Last reply
    0
    • W watagal

      Hi all, Not sure if my subject is correct in describing what I want to do. I have an integer variable (iOptions) where each bit represents an On/Off Flag: 0 = all off 1 = flag1 2 = flag2 4 = flag3 8 = flag4 ....... and so on Of course this integer variable could equal to 7 (flag1+flag2+flag3 are On) or anywhere in between. How do I write a bitwise if statement to check if anyone flag is On? if iFlag1 ?? iOptions then ' **What goes here instead of ??** ... else if iFlag2 ?? iOptions then ... end if Thanks, Karen Nooobie to OOP and VB.Net 2005

      B Offline
      B Offline
      Briga
      wrote on last edited by
      #2

      If I got it correctly you want to check a specific bit if is on or off. Several ways. Tha basic one is to OR the integer with the bit mask and check if the result is (or not) 0. if (a OR 1) = 0 then bit0_notset else bit0_set if (a OR 2) = 0 then bit1_notset else bit1_set if (a OR 4) = 0 ... Briga

      W 1 Reply Last reply
      0
      • B Briga

        If I got it correctly you want to check a specific bit if is on or off. Several ways. Tha basic one is to OR the integer with the bit mask and check if the result is (or not) 0. if (a OR 1) = 0 then bit0_notset else bit0_set if (a OR 2) = 0 then bit1_notset else bit1_set if (a OR 4) = 0 ... Briga

        W Offline
        W Offline
        watagal
        wrote on last edited by
        #3

        Briga Thanks so much! It's so simple, yet it is not discussed in any of the VB.Net books I have. OR didn't work for me, but AND did. Thanks again Thanks, Karen Nooobie to OOP and VB.Net 2005

        B 2 Replies Last reply
        0
        • W watagal

          Briga Thanks so much! It's so simple, yet it is not discussed in any of the VB.Net books I have. OR didn't work for me, but AND did. Thanks again Thanks, Karen Nooobie to OOP and VB.Net 2005

          B Offline
          B Offline
          Briga
          wrote on last edited by
          #4

          Sorry ... of course you're right is AND not OR!!!!

          1 Reply Last reply
          0
          • W watagal

            Briga Thanks so much! It's so simple, yet it is not discussed in any of the VB.Net books I have. OR didn't work for me, but AND did. Thanks again Thanks, Karen Nooobie to OOP and VB.Net 2005

            B Offline
            B Offline
            Briga
            wrote on last edited by
            #5

            Sorry, of course you're right it's AND not OR (my mistake)!!!

            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