This set of challenges is designed to be completed with a logic board such as the Logic & Arithmetic board designed by the University of Southampton and the UK Electronic Skills Foundation.

Alternatively, if you do not have access to a physical kit, you can still complete these challenges using our online logic gates circuit simulator.

#### J==K? Comparing if two inputs are equal

The following diagram is used to compare if two inputs are the same. The output (X) should be on if both inputs J and K are set to O or both inputs are set to 1. This circuit is used to implement the **comparison operator == (“is equal to”)**.

**Truth Table:**

Input J | Input K | Output X |

0 | 0 | |

0 | 1 | |

1 | 0 | |

1 | 1 |

#### J<K? Less than operator

The following diagram is used to compare if input J is strictly lower than input K. The output (X) should be on if so (e.g. when J = 0 and K = 1). This circuit is used to implement the **comparison operator < (“is less than”)**.

**Truth Table:**

Input J | Input K | Output X |

0 | 0 | |

0 | 1 | |

1 | 0 | |

1 | 1 |

#### J>K? Greater than operator

The following diagram is used to compare if input J is strictly greater than input K. The output (X) should be on if so (e.g. when J = 1 and K = 0). This circuit is used to implement the **comparison operator > (“is greater than”)**.

**Truth Table:**

Input J | Input K | Output X |

0 | 0 | |

0 | 1 | |

1 | 0 | |

1 | 1 |

#### 1-bit magnitude comparator

By combining all three logic gates circuits into one, we can create a **1-bit magnitude comparator** that takes two inputs (J and K) and produces three outputs:

- X = (J < K)
- Y = (J == K)
- Z = (J > K)

Here is the logic gates diagram for this comparator. You can recreate this circuit and test it on your logic board.

**Truth Table:**

Input J | Input K | Output X J < K ? |
Output Y J == K ? |
Output Z J > K ? |

0 | 0 | |||

0 | 1 | |||

1 | 0 | |||

1 | 1 |

#### Extension Task: !=, <= and >= Comparison Operators

How could you combine and tweak the above diagrams to create logic gates circuits to implement the following comparison operators:

**“is not equal to”**(e.g. J != K)**“is lower than or equal to”**(e.g. J <= K)**“is greater than or equal to”**(e.g. J >= K).

Design your circuits, then recreate them and test them on the logic board to see if they “behave” as you would expect!

#### Find out more…

You can find out more about binary comparators on the following pages: