You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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.
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
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
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
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
>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!
Thanks to everyone who made a useful contribution to this discussion; especially MCM who gave a crystalclear answer that definitely solves my long-existing problems in this field. Thanks Michael!
Only one minor question is unanswered so far. 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.
>for instance: %FLAG1 OR %FLAG5 = 17, which is the same as %FLAG1 + %FLAG5.
Of course it is. FLAG1 and FLAG5 are nonequal integral powers of two.
>Now the real problem: when %FLAG7 is passed, my function should initially execute as >if %FLAG2 had been passed
Hell of a design. I would have just passed FLAG2 when I wanted FLAG2.
If you will take some free advice: Just forget about adding and use the booleans
Set a bit flag : newmask = (oldmask OR desiredmask)
Turn off : newMask = (OldMask AND (NOT DesiredMask))
Is set? : ISTRUE (newMask and DesiredMask)
Yes, I always use all those parens. With "short-circuit" valuation in effect I'd rather the compiler know EXACTLY what I mean.
FWIW..
This is the code I've written and it appears to work
Code:
IF (dwCombi AND %FLAG7) THEN
dwCombi = dwCombi AND (NOT %FLAG7)
dwCombi = dwCombi OR %FLAG2
lRebuildFlag = 1 ' remember %FLAG7 was initially passed
END IF
It's certainly 'safe'.
It's correct if what you want is "If the mask comes in with FLAG7 on, turn it off, set FLAG2 in the mask and set the rebuild flag."
I'd add ELSE iRebuildFlag = %FALSE myself, since it might be set elsewhere in the code (not shown). It also makes it very clear what you are doing with that rebuild flag if you don't look at this code sometime in the next six months.
When I "OR" some of these values the result appears to be the sum, for instance: %FLAG1 OR %FLAG5 = 17, which is the same as %FLAG1 + %FLAG5. What I also need is a sequential %FLAG7. Should its value be 48 (&H00000030) or 64 (&H00000040)?
Now the real problem: when %FLAG7 is passed, my function should initially execute as if %FLAG2 had been passed (and finally do a minor edit to the result in order to match %FLAG7). Let's assume the combined values are passed as dwCombi (DWORD). This is what my function initially should do:
check if %FLAG7 is one of the values in dwCombi
if so, extract %FLAG7 from dwCombi and add %FLAG2 (note: flags 7 and 2 exclude each other and can never be OR'ed)
This is the code I've written and it appears to work. Is it correct and safe?
Code:
IF (dwCombi AND %FLAG7) THEN
dwCombi = dwCombi AND (NOT %FLAG7)
dwCombi = dwCombi OR %FLAG2
lRebuildFlag = 1 ' remember %FLAG7 was initially passed
END IF
Last edited by Egbert Zijlema; 26 Feb 2008, 11:41 AM.
Reason: wrong var name
#COMPILE EXE
#DIM ALL
FUNCTION PBMAIN () AS LONG
LOCAL A AS LONG, B AS LONG, C AS LONG
A =2&
B =4&
C = (A OR B)
MSGBOX USING$ (" # OR # = #", A, B, C)
END FUNCTION
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: