#22442 - XOR
Un article très complet sur « XOR », en programmation.
A third way to look at the same truth table is to consider each value of one of the inputs a, and look at what XOR does to the other variable b in each case:
If a = 0, then a XOR b is the same thing as just b.
If a = 1, then a XOR b is the opposite of b: 0 becomes 1 and 1 becomes 0.
So another way to look at the XOR operation is that you’re either going to leave b alone, or invert it (swapping 0 and 1), and a tells you which one to do. If you imagine XOR as a tiny computing device, you could think of the input b as ‘data’ that the device is operating on, and a as a ‘control’ input that tells the device what to do with the data, with the possible choices being ‘flip’ or ‘don’t flip’.
a XOR b means: invert b, but only if a is true.
Belle explication !
Et la toute dernière ligne ici explique assez bien la construction d’une porte XOR des AND, OR et NOT.
On l’utilise peu, mais les langages intègrent souvent "xor" comme ils intègrent "and" ou "or" (en PHP par exemple). Ou bien on utilise « ^ » quand la syntaxe prévoit « && » et « || » (comme en JS).
~
Au passage, en langue française, le « ou » est inclusif par défaut. Donc dire « et/ou » est un pléonasme. De même, quand on demande « vous prendrez le fromage ou le dessert ? », répondre « oui » est une réponse logiquement totalement acceptable… quoi que pas forcément acceptée, mais c’est toujours rigolo d’essayer, jusqu’à ce que le chef nous fout dehors (pas que ça me soit arrivé).
Sinon, pour ceux qui se demandent ce que je réponds quand on me demande de répondre par oui ou par non, je réponds évidemment « par oui ou par non ».
(Enfin, si vous aimez ces trucs de logique un peu incongrus, essayez le bouquin “Quel est le titre de ce livre”, de Raymont Smullyan (lien, ISBN : 978-2100020034)