Login
Back to forumReply to this topicGo to last reply

Posted By

SVS
on 2003-09-30
 AND OR NOT?

I need to process an XOR operation only using AND, OR, NOT boolean operators.
Then I ask for your help to solve the math problem.
I achieved this solution:

(x AND (NOT y)) OR ((NOT x) AND y)

Anybody could confirm it is right? happy

Posted By

Ulysses777
on 2003-09-30
 Re: AND OR NOT?

Yup, that's OK.

Another way is: (x OR y) AND ((NOT x) OR (NOT y)) happy

Posted By

Litwr
on 2003-10-07
 Re: AND OR NOT?

Maybe this will better? x XOR y = x+y (mod 2), i.e. add x to y and take remainder from division by 2. In C "x^y" is equal to "(x+y)%2".

Posted By

JamesC
on 2003-10-07
 Re: AND OR NOT?

That would work if SVS were using a 128, or machine language.

Limiting the options to AND, OR, and NOT indicates BASIC 2.0 to 3.5.

Posted By

Gaia
on 2003-10-07
 Re: AND OR NOT?

James C:
1. MOD 2 is equivalent to an AND 1 so it's possible to do it from BASIC as well.
2. Any MOD expression can be simulated by an INT and a division.
3. There's no MOD in machine language

Posted By

SVS
on 2003-10-07
 Re: AND OR NOT?

Thanx you all for the replies.
---> Litwr: I need a formula when x and y are decimal values, then greater than 1
---> Gaia: in machine language LSR does the same effect than MOD 2 happy
---> JamesC: ...maybe BASIC 1.0 too wink

Posted By

Gaia
on 2003-10-07
 Re: AND OR NOT?

It does not matter if the arguments are hexa or decimal. As for the LSR instruction: that is actually a division by 2, so what you get is the result of INT(argument/2). The remainder though will be shown in the carry (= the result of a %2). It's a point for argument if this can be considered a MOD instruction (IMHO not, as it is just a side effect here).

Posted By

JamesC
on 2003-10-07
 Re: AND OR NOT?

Attila, I'm not saying anything about MOD, it's the XOR that doesn't exist in BASIC 3.5. It is, however, available in BASIC 7.0, or using machine language.

SVS's original question was how to simulate XOR using the BASIC 3.5 keywords that are available (AND, OR, NOT).

>Maybe this will better? x XOR y = x+y (mod 2)

Posted By

JamesC
on 2003-10-07
 Re: AND OR NOT?

Nevermind, I just read the whole thing again. My post earlier was before my morning caffeine consumption.

Litwr's x XOR y before the = was not part of the solution; I thought it was. I did not read the post clearly.

My apologies.



Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2024. Support Plus/4 World on Patreon