Computers - Encoders

Introduction
ToDo

2-to-1 Encoder
ToDo

Source
import gates.AND; import gates.NOR; import gates.NOT; import gates.OR; import gates.XOR; public class Encoder { private Encoder{} public static boolean two_TO_one(boolean[] decoded) throws Exception{ // Checking for proper bits range if(decoded.length != 2) throw new Exception("Invalid decoded bytes range!"); // Checking for valid input else if(            !XOR.find(decoded[0], decoded[1])         ) throw new Exception("Invalid input!"); return(            ( NOR.find( NOT.find(decoded[0]), decoded[1]) ) ? false : true         ); } // OMITTED ENCODERS }

Unit Test
public static void main(String[] args){ boolean[] decodedA = { true, false }; boolean[] decodedB = { false, true }; boolean[] failA = { false, false }; boolean[] failB = { true, true }; // Good value test try { System.out.println("{true,false} = " + Encoder.two_TO_one(decodedA)); System.out.println("{false,true} = " + Encoder.two_TO_one(decodedB)); } catch (Exception e) { e.printStackTrace; }        // Bad value test- try { System.out.println("{false,false} = " + Encoder.two_TO_one(failA)); } catch (Exception e) { e.printStackTrace; }        try { System.out.println("{true,true} = " + Encoder.two_TO_one(failB)); } catch (Exception e) { e.printStackTrace; }    }

Standard Output
java.lang.Exception: Invalid input! at circuits.complex.Encoder.two_TO_one(Encoder.java:22) at tests.TestEncoder.main(TestEncoder.java:30) java.lang.Exception: Invalid input! at circuits.complex.Encoder.two_TO_one(Encoder.java:22) at tests.TestEncoder.main(TestEncoder.java:35) {true,false} = false {false,true} = true

4-to-2 Encoder
ToDo