Announcement

Collapse
No announcement yet.

How to AND/OR an OR-ed value?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    >Which value must I give to the new constant (%FLAG7): 48 OR 64? The latter is an >integral power of 2 (2^6), so - given the discussion here - I tend to prefer 64.

    ????

    This is a trick question, right?

    Ok, I'll bite anyway... you want %FLAG7 = EXP2(n) where 'n' is the (0-based) bit number you want "on" when %FLAG7 is to be "true."

    (Hint: if %flag7=48 more than one bit will have to be set which will screw up EVERYTHING!).

    BTW.. just forget about that 'integral power of two' crap I posted!. Use the boolean operators only!

    More hints
    Code:
    %FLAG0  = &b1
    %FLAG1  = &b10
    %FLAG2  = &b100 
    %FLAG3  = &b1000
    %FLAG4  = &b10000
    .....
    (Are you sensing a pattern yet?)

    MCM
    Last edited by Michael Mattias; 26 Feb 2008, 04:02 PM.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #22
      I see the pattern, yes.

      Yes Michael, I see the pattern. Everything is clear now. Thanks again.

      Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
      http://zijlema.basicguru.eu
      *** Opinions expressed here are not necessarily untrue ***

      Comment


      • #23
        Just because I like seeing my leading zero's (so easy to forget when you are thinking about a different subject)

        Code:
        #COMPILE EXE
        #DIM ALL
        #INCLUDE "Win32Api.INC"
        
        FUNCTION PBMAIN () AS LONG
        
             %FLAG0  = &b00000001
             %FLAG1  = &b00000010
             %FLAG2  = &b00000100
             %FLAG3  = &b00001000
             %FLAG4  = &b00010000
        MSGBOX BIN$(%FLAG0 AND %FLAG1, 8)
        MSGBOX BIN$(%FLAG0 OR %FLAG1, 8)
        MSGBOX BIN$(%FLAG0 AND %FLAG1 AND %FLAG2, 8)
        MSGBOX BIN$(%FLAG0 OR %FLAG1 OR %FLAG2, 8)
        MSGBOX BIN$(%FLAG0 AND %FLAG1 AND %FLAG2 AND %FLAG3, 8)
        MSGBOX BIN$(%FLAG0 OR %FLAG1 OR %FLAG2 OR %FLAG3, 8)
        MSGBOX BIN$(%FLAG0 AND %FLAG1 AND %FLAG2 AND %FLAG3 AND %FLAG4, 8)
        MSGBOX BIN$(%FLAG0 OR %FLAG1 OR %FLAG2 OR %FLAG3 OR %FLAG4, 8)
        
        END FUNCTION
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #24
          Goodness me can't believe so many posts about such a basic. Binary computers use Boolean Algebra which has only 3 basic rules, AND, OR, NOT all other functions including addition, subtraction, exclusive or etc are derived from them and can be built using a combination of these three gates in electronics. The nearest thing to a fourth basic is a flip flop which intoduces the concept of a clock and can still be built with the three basic functions.
          This doesn't even qualify to be called computing 101
          Edit Afterfought, reply may seem a bit sarcastic but just could not see the point in elegant solutions that only confused the understanding of basic boolean algebra
          Last edited by John Petty; 27 Feb 2008, 10:15 AM.

          Comment


          • #25
            The nearest thing to a fourth basic is a flip flop which ..can still be built with the three basic functions.
            To toggle (flip-flop) a bit you can use XOR (which might qualify as your 'fourth basic')

            Bit_Toggled_mask = OriginalMask XOR %FLAGn

            (I think)

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #26
              No Michael, you missed the point that the fourth basic for computing is the concept of time, a flip flop gained its name in that in its first incarnation it reversed its state on each clock cycle (the not of the output being fed back to the input) thus creating a binary divide be 2 function or combined a binary counter. Its primarily ability is that it can remember a state and so is the basis of what in programming we call today a register

              Comment


              • #27
                John, you missed a point,
                When thinking AND OR etc, you have to think "ElectroMechanical" or coding-wise you will get TOTALLY lost over a simple programming error.

                but just could not see the point in elegant solutions that only confused the understanding of basic boolean algebra
                Not sure how you meant, but to me seeing Boolean makes perfect sense vs higher levels of solutions in some cases

                (Although I still have to break down to "Bit-by-Bit" to keep my math straight when it comes to binary values)

                But at least I understand it rather than blindly saying %MyValue1 AND %MahVal2

                and expect to come up with Decimal val 4 and the reply is 5
                Engineer's Motto: If it aint broke take it apart and fix it

                "If at 1st you don't succeed... call it version 1.0"

                "Half of Programming is coding"....."The other 90% is DEBUGGING"

                "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                Comment


                • #28
                  No Michael, you missed the point that the fourth basic for computing is the concept of time
                  I do applications, not time.

                  Regardless, XOR is IMNSHO one of the four basic boolean operators (along with AND, OR, and NOT) with which everyone who wants to call himself a programmer should be familiar.

                  (You can leave the IMP club in the bag).

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment

                  Working...
                  X