I tried to make Venn diagram an easy-to-understand GIF animation

AND circuit

The AND circuit is as follows. There are inputs A and B, and the overlapping red C is the output. ベン図AND.gif

OR circuit

The OR circuit is as follows. There are inputs A and B, and the range C of A and B is the output. ベン図OR.gif

NAND circuit

The NAND circuit looks like this: It is the denial of AND that came out at the beginning. (NOT AND) You can see that the output of red C is the inversion of AND. This circuit outputs FALSE when both A and B are TRUE. ベン図NAND.gif

NOR circuit

The NOR circuit is as follows. It is a denial of OR. (NOT OR) ベン図NOR.gif

XOR circuit

The XOR circuit looks like this: Outputs FALSE when both A and B are TRUE or both are FALSE. ベン図XOR.gif

Disassembly of XOR circuit

To find the XOR circuit using NAND, OR, AND, it is as follows. When the yellow NAND and purple OR are overlapped, the overlapping range (AND) is the XOR. (The range where yellow and purple are overlapped and become whitish)

ベン図1_03.gif

Java implementation of XOR circuit

Let's implement the figure shown in the decomposition of the XOR circuit above in Java.

Main.java



public class Main {

    public static void main(String[] args) {
        //XOR circuit output
        final boolean[][] AB = {
                    { true, true },
                    { true, false },
                    { false, true },
                    { false, false }
                };

        System.out.printf("XOR circuit output\n");
        for (int i = 0; i < AB.length; i++) {
            boolean b = xor(AB[i][0], AB[i][1]);
            System.out.println("(A :" + AB[i][0] + ") + (B :" + AB[i][1] + ") = " + b);
            }
    }
    public static boolean and(boolean a, boolean b) {
        if (a && b) {
            return true;
        }
        return false;
    }

    public static boolean or(boolean a, boolean b) {
        if (a || b) {
            return true;
        }
        return false;
    }
    public static boolean nand(boolean a, boolean b) {
        return !and(a, b);
    }
    public static boolean xor(boolean a, boolean b) {
        if (and(nand(a, b), or(a,b))) {
            return true;
        }
        return false;
    }
}

//XOR circuit output
//(A :true) + (B :true) = false
//(A :true) + (B :false) = true
//(A :false) + (B :true) = true
//(A :false) + (B :false) = false

Java implementation of XOR circuit Part 2

You can also create an XOR circuit by changing the contents of the xor method used in the above Java code to the following. Below is an output like a crescent moon with the right side of a taking the and of a and nand (a, b) missing, and a crescent moon with the left side of b taking the and of b and nand (a, b) missing. Output so that the output is combined with or.

Main.java



    public static boolean xor(boolean a, boolean b) {
        if (or(and(a, nand(a, b)), and(b, nand(a, b)))) {
	    	return true;
	    }
    	return false;
    }

Recommended Posts

I tried to make Venn diagram an easy-to-understand GIF animation
I tried to make an introduction to PHP + MySQL with Docker
I tried to make an Android application with MVC now (Java)
I tried to make it an arbitrary URL using routing nesting
I want to make an ios.android app
I tried to make an automatic backup with pleasanter + PostgreSQL + SSL + docker
I tried to develop an application in 2 languages
I tried to make a login function in Java
I tried to make FizzBuzz that is uselessly flexible
I tried to draw animation with Blazor + canvas API
App development beginners tried to make an Android calculator app
Rails6 I tried to introduce Docker to an existing application
I tried to build an environment using Docker (beginner)
I tried to introduce UI animation to Pokedex using Poké API
I tried using Hotwire to make Rails 6.1 scaffold a SPA
I tried to make Java Optional and guard clause coexist
I tried to make an app that allows you to post and chat by genre ~ App overview ~
I tried to make a client of RESAS-API in Java
I tried to verify yum-cron
[Android] [Library] I tried using an animation library called "Before After animation".
After learning Progate, I tried to make an SNS application using Rails in the local environment
I tried to build an http2 development environment with Eclipse + Tomcat
[Unity] I tried to make a native plug-in UniNWPathMonitor using NWPathMonitor
[Java] I tried to make a maze by the digging method ♪
Collatz number, Fibonacci number, triangular number I tried to make various sequence programs
Rails Tutorial Extension: I tried to create an RSS feed function
I tried to make Numeron which is not good in Ruby
I tried to make a group function (bulletin board) with Rails
I tried to chew C # (indexer)
I tried to summarize iOS 14 support
I tried to interact with Java
I tried to explain the method
I tried to summarize Java learning (1)
I tried to understand nil guard
I tried to summarize Java 8 now
I tried to chew C # (polymorphism: polymorphism)
I tried to explain Active Hash
I tried to make a parent class of a value object in Ruby
I tried to make a simple face recognition Android application using OpenCV
I tried to summarize the stumbling points when developing an Android application
I tried to make a Web API that connects to DB with Quarkus
I tried to make my own transfer guide using OpenTripPlanner and GTFS
I made a virtual currency arbitrage bot and tried to make money
01. I tried to build an environment with SpringBoot + IntelliJ + MySQL (MyBatis) (Windows10)
I tried to make full use of the CPU core in Ruby
I tried to make a talk application in Java using AI "A3RT"
I tried to summarize the methods used
I tried to introduce CircleCI 2.0 to Rails app
I tried migrating Processing to VS Code
I tried to summarize Java lambda expressions
I tried to get started with WebAssembly
I tried to solve AOJ's Binary Search
I tried to implement the Iterator pattern
I tried to summarize the Stream API
I tried to build AdoptOpenjdk 11 on CentOS 7
What is Docker? I tried to summarize
I tried to build Ruby 3.0.0 from source
I tried to use Selenium like JQuery
I tried to touch JavaScript Part.2 Object-oriented
I tried to implement ModanShogi with Kinx
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~