'AND', 'OR', 'MOD', 'NOT' and 'XOR' operations

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

'AND', 'OR', 'MOD', 'NOT' and 'XOR' operations

Post by alexander70 »

Hi! I have a question about Example 27 (Calulations and use of 'AND', 'OR', 'MOD', 'NOT' and 'XOR' operations.) Where can I read more information on these operators?

Not clear why :

C = ( ( ( A << 2 ) AND 15 ) OR 85 ) >> 1 = 046
D = A * ( ( A MOD 2 ) = 0 ) = 010
E = NOT ( A XOR 60 ) = 201

( if A = 010)
Respectfully, Alexander

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 'AND', 'OR', 'MOD', 'NOT' and 'XOR' operations

Post by Benj »

Hello

This page may be of some help.
http://en.wikipedia.org/wiki/Logic_gate

Also this
http://www.learn-c.com/boolean.htm

The pages I have linked above show single bit truth tables. For 8-bit numbers you have to apply the truth table to each individual bit.

eg

01001101 - 77
AND
10101100 - 172
Equals
00001100 - 12

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: 'AND', 'OR', 'MOD', 'NOT' and 'XOR' operations

Post by alexander70 »

Thank you, I'll study it.
Respectfully, Alexander

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: 'AND', 'OR', 'MOD', 'NOT' and 'XOR' operations

Post by alexander70 »

There is a description of all operations except the 'MOD'. Where can I learn about the 'MOD' operation?
Respectfully, Alexander

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 'AND', 'OR', 'MOD', 'NOT' and 'XOR' operations

Post by Benj »

Hello

The MOD operation collects the non divisible remainder of a division.

For example

20 MOD 5 = 0
21 MOD 5 = 1
22 MOD 5 = 2
23 MOD 5 = 3
24 MOD 5 = 4
25 MOD 5 = 0

This example would count upwards a single digit at a time and then wrap around to 0 when it reaches the MOD value of 50.

count = (count + 1) MOD 50

Useful for performing loops or for creating counters that rollover at odd values.

Post Reply