Skip to content

An experiment to implement basic logic gates AND, OR & NOT, and higher level circuitry using Goalng's channels

Notifications You must be signed in to change notification settings

danishm/andornot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logic Gates Using Go Channels

I've been using Go as my primary development language for over 2 years now. I thought the language's concept of channels was pretty cool. I used to wonder if I can make simple logic gates using channels and if they can be put together to form circuits.

This is my attempt!

Examples

Trying a simple AND gate

Code

package main

import (
	"fmt"

	"github.com/danishm/andornot/gates"
)

func main() {
	board := gates.DefaultBoard()

	gate := gates.AND(board)
	gate.Pin1() <- 0
	gate.Pin2() <- 1
	out := <-gate.Out()

	fmt.Println(out)

	board.Stop()
}

Output

0

Construct a NAND gate using AND and NOT

Code

package main

import (
	"fmt"

	"github.com/danishm/andornot/gates"
)

func main() {
	board := gates.DefaultBoard()

	// Create a NAND gate
	and := gates.AND(board)
	not := gates.NOT(board)
	board.Connect(and.Out(), not.Pin1())

	// See if it works
	and.Pin1() <- 1
	and.Pin2() <- 0
	out := <-not.Out()

	fmt.Println(out)

	board.Stop()
}

Output

0

About

An experiment to implement basic logic gates AND, OR & NOT, and higher level circuitry using Goalng's channels

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages