The Boolean I Ching
The boolean I Ching displays selected hexagrams in pairs, and the hexagrams resulting from the application of the boolean operators AND, OR, XOR, XNOR, NOT, NAND, NOR, implication, and converse nonimplication.
Boolean algebra is informally applied to I Ching hexagrams during such operations as the transforming of moving lines, or the identification of the correct line in each position (explained some more below). The basic operations are as follows:





The AND operator results in a value of 1 when both of the inputs are 1. The OR operator results in a value of 1 when either of the inputs is 1. The XOR (exclusiveor) operator results in a value of 1 when either, but not both, of the inputs is 1; or in other words, when the inputs are different. The XNOR operator represents logical equality; it results in a value of 1 when both inputs are the same. And the NOT operator simply reverses 0 to 1 and vice versa; it is the opposite of logical identity.
Beyond the identification of moving or correct lines, boolean operators can be used to combine individual hexagrams in different ways. The lines of each hexagram are usually assigned values of 0 for yin and 1 for yang; each hexagram is thus represented as a sixdigit binary number. The operators are applied to the hexagrams via corresponding pairs of digits. I shall list the digits right to left (least to greatest, in binary notation) to represent lines from bottom to top (first to last). So the combinations of hexagram 6 (111010) and 61 (110011) are as follows:





The XOR operator is how strings of digits are most often combined in fields such as cryptography. However, the assignment of numeric values to yin and yang is a fairly recent invention. Moreover, boolean values are actually logical, not numeric; they could just as well be “T” and “F,” or and . (In the I Ching, they are yin and yang.) The choice of yin=0 and yang=1 is ultimately arbitrary, and the results of the XOR operator differ depending on the choice; if yin=1 and yang=0, the results are reversed. This is actually the equivalent of an easilyoverlooked operator, XNOR or logical equality. This operator is required if the system is to remain isomorphic with respect to the reversal of the values assigned to yin and yang. And if you browse through the hexagram combinations and compare XOR with XNOR, you may see some interesting results. (Try 6 and 7, for example.) Concerning the other operators, reassigning the values of yin and yang exchanges the outcomes of AND and OR; “yang if either line is yang” is equivalent to “yin if both lines are yin.” Formally:
a XOR b = NOT (a XNOR b)
a AND b = NOT ((NOT a) OR (NOT b))
This leads to a sixfold symmetry between the operations:
a  —  NOT a 
a AND b  —  a OR b 
a XOR b  —  a XNOR b 
A userfriendly way of looking at the results of applying the various operators is as follows:
• yang if the lines are different/changing (a XOR b)
• yin if the lines are different/changing (a XNOR b)
• yang if both lines are yang (a AND b)
• yin if both lines are yin (a OR b)
• line values reversed (NOT a)
Note that XOR and XNOR hexagrams form triads; if a XOR b = c, then a XOR c = b, and b XOR c = a.
I have not very often seen the AND and OR operators applied to the I Ching. They represent the yang, or yin, aspects that two hexagrams have in common.
A number of other boolean operators exist, such as NAND (yin if both lines are yang), NOR (yang if both lines are yin), implication (yin if changing yang), and converse nonimplication (yang if changing yin). They can all be derived from the basic functions above.




Boolean operators in practice
Changing a hexagram line is the equivalent of the hexagram XOR a 1 in the place of the changing line (which is actually two to the power of the number of the changing line, with the lines numbered 0 to 5). To change the fouth line of hexagram 6, Sung/Conflict, one applies XOR with 001000:

The reversed (as opposed to inverted) hexagrams, or pang tong gua, are the hexagram pairs made by applying NOT to each other, rather than physically turning them upsidedown. What I call the antihexagram is similarly the NOT of the transformed hexagram; it is what the situation is “not” changing into, or what is being avoided.
When an I Ching reading includes moving lines, the base hexagram XOR the resulting hexagram consists of the outer pattern of change, and XNOR the inner pattern of change. Another way of looking at it is that the patterns of change are representations of the moving lines; they are how you get from the base to the resulting hexagram.
Oddnumbered lines are considered correct when they are yang, and evennumbered lines similarly when they are yin. The hexagram with all correct lines is thus 63 (010101), and the one with all incorrect lines is 64 (101010). A hexagram’s correctness hexagram may be found by applying XNOR, equality, with hexagram 63, the allcorrect hexagram; or by applying XOR with hexagram 64, the allincorrect one. Either way, in the result, correct lines are yang, and incorrect ones are yin.
Another type of bitwise operator, the shift operators, shifts the bits of a binary number to the left or right. These operators are used in mathematical operations and cryptography. In an ordinary linear shift, bits on the extreme left or right are discarded, and zeroes are added to the other end to fill the empty spaces. So,
LEFT SHIFT 1  111010 
110100 
A circular shift, or bitwise rotation, is more relevant to I Ching hexagrams. In a circular shift, the discarded bits at the extreme left or right are used to fill in the gap on the other end. When applied to a hexagram, a circular shift of three bits constitutes a reversal of the trigrams. Six onebit shifts rotate the hexagram around and back to the original. The waxing and waning seasonal cycle of hexagrams consists of a subset of six lines from a circular shift of the hexagram pair Ch’ien/The Creative and K’un/The Receptive (see The Case for LittleEndian).
LEFT ROTATE 1  111010 
110101 
The script
Select hexagrams below, and the indicated operation will be applied.
Please see Andreas Schöter’s articles for a more formal treatment of the subject.
See also YinYang Code: A Introduction To IChing by Ning Lu, Ph.D., and,
On Leibniz and the IChing by Sherwin Doroudi.
Chris Lofting discusses some of the above operators, albeit in his own context.
Base 2 or base 4?
Some, especially those who seek parallels between the I Ching and the genetic code, treat hexagram lines as a base 4 system, and use digrams to represent them:
moving yin  6  6  88 
yang  7  7  78 
yin  8  8  87 
moving yang  9  9  77 
However, I believe that it is best to consider the lines as a binary, or base 2, system, with an additional bit used to represent whether a line is changing or not. If the first (rightmost) bit determines the line, and the second determines whether the line is moving, then we have:
moving yin  6  10 
yang  7  01 
yin  8  00 
moving yang  9  11 
The transformed line is found by applying XOR to the two bits. Moving yin thus become yang, and yang stays yang, because their bits are different; and yin stays yin, and moving yang become yin, because their bits are the same. (Digrams could be used to represent this as well, but in this case they are not very intuitive.)
The bits may be more logically represented as one sixdigit number representing the base hexagram, and another representing the moving lines; this second hexagram is the outer pattern of change. The equation below would represent the transformation between the two hexagrams at the top of the page:
001010  
XOR  010010 
011000 
Geek stuff
Javascript includes several logical operators that apply to ordinary numeric values, and may be familiar to those who have used it: AND, a && b; OR, a  b; equality, a == b; inequality, a != b; and NOT, !a. But a more powerful set of operators, called “bitwise operators,” apply their operations to the individual bits (zeroes and ones) of the operands. This allows I Ching hexagrams to be treated as sixbit binary integers, and compared bitbybit. The operators used here are:
AND: a & b
OR: a  b
XOR: a ^ b
LEFT SHIFT: a << b
The bitwise NOT operator, ~a, like the other bitwise operators, always treats its operands as signed 32bit integers, and so is not useful for merely reversing the bits of a sixbit integer. The way to apply NOT to individual bits is to apply XOR with a value of 1; a XOR 1 is always the reverse of a. So, in practice,
NOT: a ^ 111111
There is no javascript operator for bitwise equality, XNOR. But, thanks to the equivalence relationship above, it may be rendered as the NOT of XOR:
XNOR: (a ^ b) ^ 111111
Bitwise equality is sometimes called EQV, and Visual Basic 6 included it as an operator (but it is no longer present in VB.NET). I have called it XNOR, partly because this seems to be an established name in fields other than computer languages, and partly because it recalls its derived nature as NOT XOR.
NAND and NOR are similarly derived from NOT AND and NOT OR:
NAND: (a & b) ^ 111111
NOR: (a  b) ^ 111111
Implication and converse nonimplication are derived as (NOT a) OR b, and (NOT a) AND b:
IF a THEN b: (a ^ 111111)  b
NOT a BUT b: (a ^ 111111) & b
Bitwise rotation is a little more complicated. The linear left shift operator moves all six bits of a hexagram number to the left, which is the equivalent of multiplying it by two. So we need to move that seventh bit to the first position. The bit is identified by the operation a AND 100000, and converted to 0 or 1 by dividing it by 32. We apply the shift operation, a LEFT SHIFT 1, and then remove the seventh bit by applying AND 111111 to the result. Finally, this result OR the leftmost digit identified above gives us the final result:
a LEFT ROTATE 1: a = ((a << 1) & 111111)  ((a & 100000) / 32)