Signed or unsigned: read this first
The same eight bits mean different numbers in the two readings. In two’s complement the top bit counts as negative.
| 01111111 | 127 | 127 |
|---|---|---|
| 10000000 | 128 | -128 |
| 10000001 | 129 | -127 |
| 11111110 | 254 | -2 |
| 11111111 | 255 | -1 |
| 00000001 | 1 | 1 |
No rows match.
The Comparator has a Numeric Type setting, signed by default. The project’s notes list the same kind of setting on the Multiplier and the Divider. The Adder and Subtractor give the same bits either way; only your reading of them changes.
Comparator
Inputs A and B, three one-bit outputs: Greater, Equal, Less. By default it compares as signed numbers (F42). On 4 bits, 128 of the 256 input pairs get a different answer when you switch Numeric Type to Unsigned. Here are the first rows where the two settings disagree (outputs are Greater, Equal, Less):
| 0000 | 1000 | 1 0 0 | 0 0 1 |
|---|---|---|---|
| 0000 | 1001 | 1 0 0 | 0 0 1 |
| 0000 | 1010 | 1 0 0 | 0 0 1 |
| 0000 | 1011 | 1 0 0 | 0 0 1 |
| 0000 | 1100 | 1 0 0 | 0 0 1 |
| 0000 | 1101 | 1 0 0 | 0 0 1 |
| 0000 | 1110 | 1 0 0 | 0 0 1 |
| 0000 | 1111 | 1 0 0 | 0 0 1 |
No rows match.
Downloads, each checked against its full table: signed, unsigned. To build a comparator from gates, see the full adder project and the ALU project.
Adder
Inputs A and B, a carry in, a sum output and a carry out. The tables below come from the 4-bit Adder with carry in as a pin (F44 lists the ports):
| 0001 | 0010 | 0 | 0011 | 0 |
|---|---|---|---|---|
| 0001 | 0010 | 1 | 0100 | 0 |
| 0111 | 0001 | 0 | 1000 | 0 |
| 1111 | 0001 | 0 | 0000 | 1 |
| 1111 | 1111 | 1 | 1111 | 1 |
No rows match.
A carry out of 1 with a sum of 0000 means the sum did not fit in 4 bits. The Adder has no overflow output. For signed numbers, overflow occurs when both inputs have the same sign and the sum has the opposite sign; this is the standard rule and we did not build it. We did not test what an unconnected carry-in does, so wire it to a constant 0.
Download the 4-bit adder: all 512 input combinations match its table.
A 16-bit adder from two 8-bit adders
Split each 16-bit number into two bytes, add the low bytes, send the carry out of the low Adder to the carry in of the high Adder, and join the two sums with a splitter. See Splitters.
Describe this circuit
Components: Input pin A; Input pin B; Splitter 1; Splitter 2; Adder 1; Adder 2; Constant 1; Splitter 3; Output pin S; Output pin Cout.
- Input pin A connects to Splitter 1 (net A), 16 bits wide.
- Input pin B connects to Splitter 2 (net B), 16 bits wide.
- Splitter 1 connects to Adder 1 (net alo), 8 bits wide.
- Splitter 1 connects to Adder 2 (net ahi), 8 bits wide.
- Splitter 2 connects to Adder 1 (net blo), 8 bits wide.
- Splitter 2 connects to Adder 2 (net bhi), 8 bits wide.
- Adder 1 connects to Splitter 3 (net slo), 8 bits wide.
- Adder 1 connects to Constant 1.
- Adder 1 connects to Adder 2 (net c).
- Adder 2 connects to Splitter 3 (net shi), 8 bits wide.
- Adder 2 connects to Output pin Cout (net Cout).
- Splitter 3 connects to Output pin S (net S), 16 bits wide.
Download the circuit.
Subtractor
Minuend M, subtrahend S, a borrow in, a difference and a borrow out. The borrow out is 1 when the difference is negative.
| 0101 | 0011 | 0 | 0010 | 0 |
|---|---|---|---|---|
| 0101 | 0011 | 1 | 0001 | 0 |
| 0000 | 0001 | 0 | 1111 | 1 |
| 0011 | 0101 | 0 | 1110 | 1 |
No rows match.
Download the 4-bit subtractor. A common alternative is an adder with XOR gates on one input and the carry in set to 1; see the adder projects.
Multiplier
The Multiplier gives the low bits of the product in its output and the upper bits on the carry-out port; the carry-in port adds an amount. For the 3-bit part (F44):
| 010 | 011 | 000 | 110 | 000 |
|---|---|---|---|---|
| 111 | 111 | 000 | 001 | 110 |
| 111 | 111 | 111 | 000 | 111 |
| 100 | 100 | 000 | 000 | 010 |
No rows match.
7 × 7 = 49 is 110001: the output holds 001 and the carry out holds 110. We did not compare the signed and unsigned types of the Multiplier. A Divider is in the library too, with dividend, divisor, quotient and remainder; we did not test it and give no result for division by zero.
Shifter
The Shifter has a Shift Type: Logical Left, Logical Right, Arithmetic Right, Rotate Left or Rotate Right. The distance input is as wide as needed to count the data bits. We tested three types on 4 bits; the table shows 1001 shifted by each distance:
| 0 | 1001 | 1001 | 1001 |
|---|---|---|---|
| 1 | 0010 | 1100 | 1100 |
| 2 | 0100 | 0110 | 1110 |
| 3 | 1000 | 0011 | 1111 |
No rows match.
Downloads: logical left, rotate right, arithmetic right. We did not test Logical Right or Rotate Left.
Negator, Bit Adder and Bit Finder
The Negator gives the two’s complement negation. On 4 bits, 1000 (−8) negates to 1000, because +8 does not fit:
| 0000 | 0000 |
|---|---|
| 0001 | 1111 |
| 0010 | 1110 |
| 0011 | 1101 |
| 0100 | 1100 |
| 0101 | 1011 |
| 0110 | 1010 |
| 0111 | 1001 |
| 1000 | 1000 |
| 1001 | 0111 |
| 1010 | 0110 |
| 1011 | 0101 |
| 1100 | 0100 |
| 1101 | 0011 |
| 1110 | 0010 |
| 1111 | 0001 |
No rows match.
The Bit Adder counts the 1 bits in its input:
| 0000 | 000 |
|---|---|
| 0001 | 001 |
| 0010 | 001 |
| 0011 | 010 |
| 0100 | 001 |
| 0101 | 010 |
| 0110 | 010 |
| 0111 | 011 |
| 1000 | 001 |
| 1001 | 010 |
| 1010 | 010 |
| 1011 | 011 |
| 1100 | 010 |
| 1101 | 011 |
| 1110 | 011 |
| 1111 | 100 |
No rows match.
The Bit Finder reports whether a bit is present and the index of the lowest-order 1 (its default Type):
| 0000 | 0 | 00 |
|---|---|---|
| 0001 | 1 | 00 |
| 0010 | 1 | 01 |
| 0011 | 1 | 00 |
| 0100 | 1 | 10 |
| 0101 | 1 | 00 |
| 0110 | 1 | 01 |
| 0111 | 1 | 00 |
| 1000 | 1 | 11 |
| 1001 | 1 | 00 |
| 1010 | 1 | 01 |
| 1011 | 1 | 00 |
| 1100 | 1 | 10 |
| 1101 | 1 | 00 |
| 1110 | 1 | 01 |
| 1111 | 1 | 00 |
No rows match.
The other Bit Finder types, such as highest-order 1, were not tested.
Newer parts
Parts first listed in 4.1.0 in our component list:
| Exponentiator | Raises one integer input to the power of another. |
|---|---|
| Square Root | Computes the integer square root of its input. |
| Absolute | Outputs the absolute value of a signed integer. |
| Minimum and Maximum | Outputs the smaller or larger of its inputs. |
| Floating Point Exponentiator | Raises a floating-point value to a power. |
| Floating Point Logarithm | Computes a logarithm of a floating-point value. |
| Floating Point Square Root | Square root of a floating-point value. |
| Floating Point Absolute | Absolute value of a floating-point number. |
| Floating Point Minimum and Maximum | Smaller or larger of floating-point inputs. |
| Floating Point Round | Rounds a floating-point value (e.g. floor, ceiling, nearest). |
| Floating Point Trigonometry | Sine, cosine and related functions on floating-point values. |
| Floating Point Classificator | Reports whether a floating-point value is zero, infinite, NaN, negative and so on. |
| Floating Point Converter | Converts between floating-point formats (16/32/64-bit). |
| Dual Port RAM | RAM with two independent access ports. |
| DMA engine | Memory-to-memory copy engine on the SoC bus (added 4.1.0). |
No rows match.
The Floating Point Arithmetic library is separate; see the component reference filtered to it.
When your lab says “build it from gates”
Use the built-in part to check your own design. Run the same 4-bit vector against both and compare the tables; see Test vectors when available, and the full adder project.