CircuitVerse Project16-Bit Calculator
Group G

16-Bit Calculator

Add and subtract two 16-bit numbers in CircuitVerse.

Try the calculator Set A, B and the mode M, then read the 16-bit result and Cout. Can you make 16 bits overflow? Try FFFF + 0001, or subtract a bigger number from a smaller one and spot the borrow.

Project overview

16bits in each input, A and B
16one-bit full adders in a chain
Mmode switch: 0 adds, 1 subtracts
Coutcarry or borrow flag

Our calculator adds and subtracts two 16-bit numbers, A and B. It is built in CircuitVerse from sixteen one-bit full adders. The carry-out of each adder goes into the carry-in of the next one, starting at bit 0 (the rightmost bit) and ending at bit 15.

A mode switch called M picks the operation. Set M = 0 to add. Set M = 1 to subtract. When M = 1, the circuit flips every bit of B and adds 1, which gives A - B.

The circuit shows a 16-bit result and a carry-out called Cout. In add mode, Cout = 1 means the sum is too big for 16 bits (a carry). In subtract mode, Cout = 1 means no borrow (A is greater than or equal to B), and Cout = 0 means there was a borrow (A is less than B).

Our team

Group: G

MemberContribution
Balanlay, Adam Samuel[What this member did]
Fortes, Axel Dirk[What this member did]
Gingging, Ria Fatima[What this member did]
Gokotano, Ray Nathaniel[What this member did]
Murry, Ralph[What this member did]
Royo, Paolo[What this member did]

How to use the calculator

Steps

  1. Click Open in CircuitVerse and select Launch Simulator if it appears.
  2. Set the 16-bit input A.
  3. Set the 16-bit input B.
  4. Set the mode M: 0 for addition, 1 for subtraction.
  5. Read the 16-bit result and Cout.

Reading carry and borrow

ModeCout = 1Cout = 0
M = 0 (add)CarryNo carry
M = 1 (subtract)No borrowBorrow

Remember: in subtract mode the meaning of Cout is reversed. Cout = 0 means A is less than B.

The circuit

CircuitVerse diagram of the 16-bit calculator showing 32 top input pins for A and B, the mode switch on the far right, sixteen XOR gates feeding sixteen full adders connected in a carry chain, sixteen sum output pins along the bottom, and the carry-out pin at the bottom left.
Click the diagram to inspect it at full resolution.

Circuit test record

All 12 test cases and the mode-switch check tested in CircuitVerse:

Case Mode A B Expected result Observed result Expected status Observed status Pass/Fail
1 0 (Add) 0000 0000 0000 0000 (0000) 0000 0000 0000 0000 (0000) 0000 0000 0000 0000 (0000) 0000 0000 0000 0000 (0000) Cout = 0 (No carry) Cout = 0 (No carry) Pass
2 0 (Add) 0000 0000 0000 0010 (0002) 0000 0000 0000 0011 (0003) 0000 0000 0000 0101 (0005) 0000 0000 0000 0101 (0005) Cout = 0 (No carry) Cout = 0 (No carry) Pass
3 0 (Add) 0000 0000 1111 1111 (00FF) 0000 0000 0000 0001 (0001) 0000 0001 0000 0000 (0100) 0000 0001 0000 0000 (0100) Cout = 0 (No carry) Cout = 0 (No carry) Pass
4 0 (Add) 0111 1111 1111 1111 (7FFF) 0000 0000 0000 0001 (0001) 1000 0000 0000 0000 (8000) 1000 0000 0000 0000 (8000) Cout = 0 (No carry) Cout = 0 (No carry) Pass
5 0 (Add) 1000 0000 0000 0000 (8000) 1000 0000 0000 0000 (8000) 0000 0000 0000 0000 (0000) 0000 0000 0000 0000 (0000) Cout = 1 (Carry) Cout = 1 (Carry) Pass
6 0 (Add) 1111 1111 1111 1111 (FFFF) 0000 0000 0000 0001 (0001) 0000 0000 0000 0000 (0000) 0000 0000 0000 0000 (0000) Cout = 1 (Carry) Cout = 1 (Carry) Pass
7 0 (Add) 0000 0000 0000 0101 (0005) 0000 0000 0000 0011 (0003) 0000 0000 0000 1000 (0008) 0000 0000 0000 1000 (0008) Cout = 0 (No carry) Cout = 0 (No carry) Pass
8 1 (Sub) 0000 0000 0000 0101 (0005) 0000 0000 0000 0011 (0003) 0000 0000 0000 0010 (0002) 0000 0000 0000 0010 (0002) Cout = 1 (No borrow) Cout = 1 (No borrow) Pass
9 1 (Sub) 0000 0001 0000 0000 (0100) 0000 0000 0000 0001 (0001) 0000 0000 1111 1111 (00FF) 0000 0000 1111 1111 (00FF) Cout = 1 (No borrow) Cout = 1 (No borrow) Pass
10 1 (Sub) 0001 0010 0011 0100 (1234) 0001 0010 0011 0100 (1234) 0000 0000 0000 0000 (0000) 0000 0000 0000 0000 (0000) Cout = 1 (No borrow) Cout = 1 (No borrow) Pass
11 1 (Sub) 0000 0000 0000 0000 (0000) 0000 0000 0000 0001 (0001) 1111 1111 1111 1111 (FFFF) 1111 1111 1111 1111 (FFFF) Cout = 0 (Borrow) Cout = 0 (Borrow) Pass
12 1 (Sub) 0000 0000 0000 0011 (0003) 0000 0000 0000 0101 (0005) 1111 1111 1111 1110 (FFFE) 1111 1111 1111 1110 (FFFE) Cout = 0 (Borrow) Cout = 0 (Borrow) Pass
Mode-Switch 0 → 1 0000 0000 0000 0101 (0005) 0000 0000 0000 0011 (0003) 0008 → 0002 0008 → 0002 Cout = 0 → Cout = 1 Cout = 0 → Cout = 1 Pass

Worked examples

Example 1: addition, 00FF + 0001 (Test Record Case 3)

  • Mode M = 0 (add)
  • A 0000 0000 1111 1111 (hex 00FF, decimal 255)
  • B 0000 0000 0000 0001 (hex 0001, decimal 1)
  • Expected 0100, carry 0
  • Observed 0100, Cout = 0
  • Meaning 255 + 1 = 256. It fits in 16 bits, so there is no carry.

Example 2: subtraction, 0003 - 0005 (Test Record Case 12)

  • Mode M = 1 (subtract)
  • A 0000 0000 0000 0011 (hex 0003, decimal 3)
  • B 0000 0000 0000 0101 (hex 0005, decimal 5)
  • Expected FFFE, borrow 1
  • Observed FFFE, Cout = 0, so there is a borrow
  • Meaning FFFE is 65,534. 65,534 - 65,536 = -2, which is 3 - 5. The borrow shows that A is less than B.

Open the live circuit

The project is set to Public, so you can run it without signing in.

Open in CircuitVerse

Calculator

Input checker

Enter exactly 16 binary digits (only 0 and 1) in each field. Keep the leading zeros. This page only checks your entries. CircuitVerse does the calculation.

Calculator inputs
0/16
0/16

Back to top