Binary Logic

From Homebrew Patent Unknown Wiki
Jump to navigation Jump to search

Binary Logic is the basis of all computer systems. If you've got something digital, by definition, it uses binary logic. Most binary logic comes in the form of Combinational Logic, though it can also come in the form of Sequential Logic. Binary is the usage of only 2 numbers, which are 0 and 1. Meaning that if you're using any numbers other than 0 or 1, you're not using binary.

Converting to Binary

In order to make a number in Homebrew work with Binary Logic, you'll need to change it into a binary number. There are two different ways a number can be converted into Binary. The first way is by converting a number into its binary equivalent. However, that is unnecessary and rather complicated in Homebrew. If you'd like to learn how, Here's a tutorial. You'll need to make rather complicated systems in order to use that though. However, since it is pointless to do in Homebrew, we'll be using the other way. Quite simply put, this method will make values greater than 0.5 into a 1, and values equal to or less than 0.5 into a 0.

Active Binary Converter
inactive Binary Converter

Attach the number you want to convert to the Trigger input of the Transistor, and the Transistor's output will be the converted Binary number, ready for use in binary logic. Note that the Toggle Box is set to always toggle and the Transistor is not set to always trigger. It is possible to perform a binary inversion on the output by simply ticking the "Triggered By Default" setting on the Transistor Box. This will cause numbers greater than 0.5 into a 0, and numbers less than or equal to 0.5 turn into 1.

  • Alternatively use a Round Box set to "Round" instead of the Transistor. This will cause values between -0.5 and 0.4999 to become 0, and values between 0.5 and 1.4999 to become a 1. Values larger than those will be larger than 1 though, and may will not be useful in Binary.

Combinational Logic Gates

Combinational Logic defines a logic system that, given the same inputs, will always give the same outputs. As opposed to Sequential Logic where the logic system stores a value and modifies it based on an input. Normally when you're working with binary logic, you have names that can quickly identify the part you're after. They use names like NAND Gate or XNOR Gate. Homebrew does not do this. Instead, you have to make your own versions of these parts. The purpose of this section is to teach you, the reader, exactly how to make your own Combinational Logic Gates.

There are 7 main types of Combinational Logic Gates. These are: AND, OR, NOT, NAND, NOR, XOR, and XNOR. Note that "XOR" may also be known as "EOR," and "NOT" may also be known as "INV," though both of these are fairly archaic. XOR and EOR both stand for "Exclusive OR" and mean the same thing. "INV" stands for "Inverter," meaning a binary inverter, but had been replaced in favor of the term "NOT," meaning exactly what it spells. The XNOR gate is "Exclusive NOR."

AND gate
OR Gate
NOT Gate
XOR Gate
XNOR Gate

Now that you've seen how to make an AND, OR, XOR and NOT gate, it's time to learn how to make NAND, NOR and XNOR. These mean "Not AND," "Not OR," and "Exclusive NOR" respectively. All you have to do is stick a NOT gate on the end of an AND, OR, or XOR gate to make NAND, NOR, and XNOR gates. Just take the NOT gate you made above, and feed the output of your AND, OR, or XOR gate into the input of your binary inverter.

Usage of Combinational Logic Gates

Combinational Logic is useful when you want to create specific conditions for something to activate. For example, if you wanted to make a car flash strobe lights when the engine is started but nobody is in the car, you'd use a combinational logic system to do that. The logic expression will be explained later in this tutorial, but it would look like this: ~AB. In other words, You'd use a NOT gate on the input A, which is your "Is Seated" output of the seat, with an AND gate. B would then be a Toggle Box that feeds into the "Activate" input of the engine. Both your ~A (Not A) and your B would be fed into the AND gate, then the output of the AND gate would be fed into an Electric Switch that controls a Strobe Light.

Truth Table

Every combinational logic system uses a Truth Table to define its outputs in terms of its inputs. In short, the Truth Table shows you exactly what the logic system will do for every possible input. They're very useful for every aspect of analyzing a logic system, and are the backbone of logic systems. Here's the Truth Table of that logic system in the previous section:

A B Output
0 0 0
0 1 1
1 0 0
1 1 0

A Truth Table works by assigning each possible input a binary number, and going through every possible combination involved, taking note of the output the logic system makes for each input combination. The letters above each column represent the input's name, and the numbers below that represent the binary value of that input. Each combination is associated with a specific output, shown as the right-most value in each row. The above truth table shows that when A is 0, and B is 0, the output will be 0. Going further, when A is 0 and B is 1, the output is 1. When A is 1 and B is 0, the output is 0. And when A is 1 and B is 1, the output is 0.

Truth Tables are extremely useful and are the easiest part of a logic system to make. When you want to make a logic system that fulfills some role, such as determining when an action should be performed, you probably already know what conditions will need to be met for that action to happen. For instance, if you want a light to turn on whenever your Pitch, Roll and Yaw are all 0. You'll need to convert each input to Binary first though, as described above. After that, you'd start by identifying how many inputs you have. In this case, there are 3. One for Pitch, one for Roll, and one for Yaw. Then you'd identify the conditions each must fulfill in order to make an output from your logic system. Once you've got those, you can start making your Truth Table. Start by drawing out the input columns, like so:

A B C Output
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

Then you'd fill in the output column as well. Filling in a 1 whenever you want that light to come on, and a 0 whenever you don't.

A B C Output
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 0

From there you can create your Logic Expression.

Further reading Wikipedia: Truth Tables

Logic Expressions

Logic Expressions are used to help communicate what a logic system does. The two most common forms of logic expressions are SOP (Sum of Products) and POS (Product of Sums), though SOP is more common than POS. For the sake of convenience and saving of headaches, SOP format will be used throughout this tutorial. Logic expressions use a number of inputs and show how they relate to each other in order to make an output true, or 1. Only combinations of inputs that make the entire system output a 1 are listed. Note that when listing an input, such as A, it is assumed to be 1 unless otherwise specified.

Logic expressions may be very useful, but they come with their own symbols to represent combinational logic functions.

Logic Gate Most common expression Alternate expression
A and B AB A*B
A or B A+B
Not A ~A -A
A XOR B A⊕B A o+ B
A XNOR B A⊙B A o- B

SOP logic expressions look like ~AB, exactly like earlier. An SOP logic expression with 3 inputs would look something like this: AB+AC+BC. This expression translates to mean: (A and B) or (A and C) or (B and C). Meaning that if inputs A and B were both 1, A and C were both 1, or if B and C were both 1, then this logic system would output a 1. Any of those 3 combinations of inputs would make the output of the logic system 1. Here is the Truth Table for that expression:

A B C Output
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1

As you can see, not only does the system output a 1 when any of those 3 conditions listed before are met, but it also outputs a 1 when multiple are met, as seen in the last line of the Truth Table. In actuality, the full expression of this logic system would be AB+AC+BC+ABC, however, the ABC part is redundant, and has been simplified out.

Another example would be the other Truth Table from earlier:

A B C Output
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 0

This one is much easier to form a Logic Expression, since only 1 line has a non-zero output. The only time that happens with this logic system, is when all 3 inputs are 0. So the logic expression would be ~A~B~C, or ~(ABC)

Further reading

Simplifying Logic Expressions

There are many ways to simplify a logic expression. One such method is Boolean Algebra. However, due to its complexity, it will be omitted from this tutorial. Karnaugh Mapping (K-mapping) will take its place, as K-Maps are much easier to learn. We'll start with a 4-input Truth Table for the following expression: A~B+AB+C~D+CD.

A B C D Output
0 0 0 0 0
0 0 0 1 0
0 0 1 0 1
0 0 1 1 1
0 1 0 0 0
0 1 0 1 0
0 1 1 0 1
0 1 1 1 1
1 0 0 0 1
1 0 0 1 1
1 0 1 0 1
1 0 1 1 1
1 1 0 0 1
1 1 0 1 1
1 1 1 0 1
1 1 1 1 1

As you can tell, that's a rather large Truth Table. K-Maps help to solve that issue, and help to even further simplify a logic expression. K-Mapping takes the output from each possible input and groups them in a grid, like so:

~C~D ~CD CD C~D
~A~B 0 0 1 1
~AB 0 0 1 1
AB 1 1 1 1
A~B 1 1 1 1

Much smaller, right? Well, K-Mapping also groups those down even further. K-Maps group outputs in pairs of 1x2, 2x2, 2x4, or 4x4. Further reading. As it turns out, this expression can be grouped into two groups of 4x2. Everything column with C in it (excluding ~C) has a 1. Thus forming the 2x4 group "C." The same can be said for each row with an A (excluding ~A). So another 4x2 group "A" can be formed. Now take the two groups and form an OR statement between them, producing A+C. This is the fully simplified version of the original logic expression, A~B+AB+C~D+CD. As you may notice in the Truth Table, any time either the column for A or C has a 1 in it, the output for that row will also have a 1.

Creating Logic Systems from expressions

Logic expressions, especially fully simplified ones, are also useful for creating logic systems, not just communicating their outputs. One of the many strengths of using SOP logic expressions is simply because they're easy to implement. Though POS logic expressions are implemented exactly the same way, they are much more difficult to simplify. Any time you have two inputs separated by a +, that means you'd use an OR gate. Likewise with ~ using a NOT gate, and * using an AND gate. For example, the expression AB+AC+BC is very easy to implement. It uses 3 AND Gates and a 3-input OR gate. In Homebrew, it would look like this:

AB+AC+BC Homebrew logic expression

Note the three Toggle Boxes show the feeds for A, B, and C. The current input is 1012, or A~BC. This system registers as true and outputs a 1 since A and C are both active. The middle three Combine Boxes are set to multiply, forming AND gates, and the right-most Combine Box is set to Add, making it an OR gate.