# Arithmetic

### Class `bw.arithmetic.Adder4` ### __init__

```__init__(
carry_in,
a_bus,
b_bus,
carry_out,
sum_bus
)
```

#### Args:

• `carry_in`: An object of type `Wire`. The carry-in to the adder.
• `a_bus`: An object of type `Bus4`. The first addend. `a_bus` and `a_bus` are the most and least significant bit, respectively.
• `b_bus`: An object of type `Bus4`. The second addend. `b_bus` and `b_bus` are the most and least significant bit, respectively.
• `carry_out`: An object of type `Wire`. The carry-out of the adder.
• `sum_bus`: An object of type `Bus4`. The sum of the two addends. `sum_bus` and `sum_bus` are the most and least significant bit, respectively.

#### Raises:

• `TypeError`: If either `a_bus`, `b_bus`, or `sum_bus` is not a bus of width 4.

### __str__

Print out the wire values of the 4-bit adder.

```carry_in: 0
a_bus: (0, 0, 0, 0)
b_bus: (0, 0, 0, 0)
carry_out: 0
sum_bus: (0, 0, 0, 0)
```

### __call__

```__call__(
carry_in=None,
a_bus=None,
b_bus=None,
carry_out=None,
sum_bus=None
)
```

Force specific values on the wires of the 4-bit adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

### Class `bw.arithmetic.Adder8` ### __init__

```__init__(
carry_in,
a_bus,
b_bus,
carry_out,
sum_bus
)
```

#### Args:

• `carry_in`: An object of type `Wire`. The carry-in to the adder.
• `a_bus`: An object of type `Bus8`. The first addend. `a_bus` and `a_bus` are the most and least significant bit, respectively.
• `b_bus`: An object of type `Bus8`. The second addend. `b_bus` and `b_bus` are the most and least significant bit, respectively.
• `carry_out`: An object of type `Wire`. The carry-out of the adder.
• `sum_bus`: An object of type `Bus8`. The sum of the two addends. `sum_bus` and `sum_bus` are the most and least significant bit, respectively.

#### Raises:

• `TypeError`: If either `a_bus`, `b_bus`, or `sum_bus` is not a bus of width 8.

### __str__

Print out the wire values of the 8-bit adder.

```carry_in: 0
a_bus: (0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0)
carry_out: 0
sum_bus: (0, 0, 0, 0, 0, 0, 0, 0)
```

### __call__

```__call__(
carry_in=None,
a_bus=None,
b_bus=None,
carry_out=None,
sum_bus=None
)
```

Force specific values on the wires of the 8-bit adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

### Class `bw.arithmetic.Adder16` ### __init__

```__init__(
carry_in,
a_bus,
b_bus,
carry_out,
sum_bus
)
```

#### Args:

• `carry_in`: An object of type `Wire`. The carry-in to the adder.
• `a_bus`: An object of type `Bus16`. The first addend. `a_bus` and `a_bus` are the most and least significant bit, respectively.
• `b_bus`: An object of type `Bus16`. The second addend. `b_bus` and `b_bus` are the most and least significant bit, respectively.
• `carry_out`: An object of type `Wire`. The carry-out of the adder.
• `sum_bus`: An object of type `Bus16`. The sum of the two addends. `sum_bus` and `sum_bus` are the most and least significant bit, respectively.

#### Raises:

• `TypeError`: If either `a_bus`, `b_bus`, or `sum_bus` is not a bus of width 16.

### __str__

Print out the wire values of the 16-bit adder.

```carry_in: 0
a_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
carry_out: 0
sum_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
```

### __call__

```__call__(
carry_in=None,
a_bus=None,
b_bus=None,
carry_out=None,
sum_bus=None
)
```

Force specific values on the wires of the 16-bit adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

### Class `bw.arithmetic.AdderSubtractor4` ### __init__

```__init__(
a_bus,
b_bus,
overflow,
carry_out,
sum_bus
)
```

#### Args:

• `add_subtract`: An object of type `Wire`. Indicates the operation to carry out - 0 for addition, 1 for subtraction.
• `a_bus`: An object of type `Bus4`. The first addend, or the minuend. `a_bus` and `a_bus` are the most and least significant bit, respectively. `a_bus` is the sign bit in subtraction operations.
• `b_bus`: An object of type `Bus4`. The second addend, or the subtrahend. `b_bus` and `b_bus` are the most and least significant bit, respectively. `b_bus` is the sign bit in subtraction operations.
• `overflow`: An object of type `Wire`. The overflow indicator of the subtractor.
• `carry_out`: An object of type `Wire`. The carry-out of the adder.
• `sum_bus`: An object of type `Bus4`. The sum of the two addends, or the difference between the minuend and the subtrahend. `sum_bus` and `sum_bus` are the most and least significant bit, respectively. `sum_bus` is the sign bit in subtraction operations.

#### Raises:

• `TypeError`: If either `a_bus`, `b_bus`, or `sum_bus` is not a bus of width 4.

### __str__

Print out the wire values of the 4-bit adder-subtractor.

```add_subtract: 0
a_bus: (0, 0, 0, 0)
b_bus: (0, 0, 0, 0)
overflow: 0
carry_out: 0
sum_bus: (0, 0, 0, 0)
```

### __call__

```__call__(
a_bus=None,
b_bus=None,
overflow=None,
carry_out=None,
sum_bus=None
)
```

Force specific values on the wires of the 4-bit adder-subtractor.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

### Class `bw.arithmetic.AdderSubtractor8` ### __init__

```__init__(
a_bus,
b_bus,
overflow,
carry_out,
sum_bus
)
```

#### Args:

• `add_subtract`: An object of type `Wire`. Indicates the operation to carry out - 0 for addition, 1 for subtraction.
• `a_bus`: An object of type `Bus8`. The first addend, or the minuend. `a_bus` and `a_bus` are the most and least significant bit, respectively. `a_bus` is the sign bit in subtraction operations.
• `b_bus`: An object of type `Bus8`. The second addend, or the subtrahend. `b_bus` and `b_bus` are the most and least significant bit, respectively. `b_bus` is the sign bit in subtraction operations.
• `overflow`: An object of type `Wire`. The overflow indicator of the subtractor.
• `carry_out`: An object of type `Wire`. The carry-out of the adder.
• `sum_bus`: An object of type `Bus8`. The sum of the two addends, or the difference between the minuend and the subtrahend. `sum_bus` and `sum_bus` are the most and least significant bit, respectively. `sum_bus` is the sign bit in subtraction operations.

#### Raises:

• `TypeError`: If either `a_bus`, `b_bus`, or `sum_bus` is not a bus of width 8.

### __str__

Print out the wire values of the 8-bit adder-subtractor.

```add_subtract: 0
a_bus: (0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0)
overflow: 0
carry_out: 0
sum_bus: (0, 0, 0, 0, 0, 0, 0, 0)
```

### __call__

```__call__(
a_bus=None,
b_bus=None,
overflow=None,
carry_out=None,
sum_bus=None
)
```

Force specific values on the wires of the 8-bit adder-subtractor.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

### Class `bw.arithmetic.AdderSubtractor16` ### __init__

```__init__(
a_bus,
b_bus,
overflow,
carry_out,
sum_bus
)
```

#### Args:

• `add_subtract`: An object of type `Wire`. Indicates the operation to carry out - 0 for addition, 1 for subtraction.
• `a_bus`: An object of type `Bus16`. The first addend, or the minuend. `a_bus` and `a_bus` are the most and least significant bit, respectively. `a_bus` is the sign bit in subtraction operations.
• `b_bus`: An object of type `Bus16`. The second addend, or the subtrahend. `b_bus` and `b_bus` are the most and least significant bit, respectively. `b_bus` is the sign bit in subtraction operations.
• `overflow`: An object of type `Wire`. The overflow indicator of the subtractor.
• `carry_out`: An object of type `Wire`. The carry-out of the adder.
• `sum_bus`: An object of type `Bus16`. The sum of the two addends, or the difference between the minuend and the subtrahend. `sum_bus` and `sum_bus` are the most and least significant bit, respectively. `sum_bus` is the sign bit in subtraction operations.

#### Raises:

• `TypeError`: If either `a_bus`, `b_bus`, or `sum_bus` is not a bus of width 16.

### __str__

Print out the wire values of the 16-bit adder-subtractor.

```add_subtract: 0
a_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
overflow: 0
carry_out: 0
sum_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
```

### __call__

```__call__(
a_bus=None,
b_bus=None,
overflow=None,
carry_out=None,
sum_bus=None
)
```

Force specific values on the wires of the 16-bit adder-subtractor.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

### Class `bw.arithmetic.FullAdder` ### __init__

```__init__(
carry_in,
a,
b,
carry_out,
sum
)
```

#### Args:

• `carry_in`: An object of type `Wire`. The carry-in to the adder.
• `a`: An object of type `Wire`. The first addend.
• `b`: An object of type `Wire`. The second addend.
• `carry_out`: An object of type `Wire`. The carry-out of the adder.
• `sum`: An object of type `Wire`. The sum of the two addends.

### __str__

Print out the wire values of the full adder.

```carry_in: 0
a: 0
b: 0
carry_out: 0
sum: 0
```

### __call__

```__call__(
carry_in=None,
a=None,
b=None,
carry_out=None,
sum=None
)
```

Force specific values on the wires of the full adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

### Class `bw.arithmetic.HalfAdder` ### __init__

```__init__(
a,
b,
carry_out,
sum
)
```

#### Args:

• `a`: An object of type `Wire`. The first addend.
• `b`: An object of type `Wire`. The second addend.
• `carry_out`: An object of type `Wire`. The carry-out of the adder.
• `sum`: An object of type `Wire`. The sum of the two addends.

### __str__

Print out the wire values of the half adder.

```a: 0
b: 0
carry_out: 0
sum: 0
```

### __call__

```__call__(
a=None,
b=None,
carry_out=None,
sum=None
)
```

Force specific values on the wires of the half adder.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

## Multiplier2

### Class `bw.arithmetic.Multiplier2` Defined in bitwise/arithmetic/MULT.py.

2-bit unsigned array multiplier.

### __init__

```__init__(
a_1,
a_2,
b_1,
b_2,
product_bus
)
```

Construct a new 2-bit unsigned multiplier.

#### Args:

• `a_1`: An object of type `Wire`. The most significant bit of the multiplicand.
• `a_2`: An object of type `Wire`. The least significant bit of the multiplicand.
• `b_1`: An object of type `Wire`. The most significant bit of the multiplier.
• `b_2`: An object of type `Wire`. The least significant bit of the multiplier.
• `product_bus`: An object of type `Bus4`. The product. `product_bus` and `product_bus` are the most and least significant bit, respectively.

#### Raises:

• `TypeError`: If `product_bus` is not a bus of width 4.

### __str__

Print out the wire values of the 2-bit unsigned multiplier.

```a_1: 0
a_2: 0
b_1: 0
b_2: 0
product_bus: (0, 0, 0, 0)
```

### __call__

```__call__(
a_1=None,
a_2=None,
b_1=None,
b_2=None,
product_bus=None
)
```

Force specific values on the wires of the 2-bit unsigned multiplier.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

## Multiplier4

### Class `bw.arithmetic.Multiplier4` Defined in bitwise/arithmetic/MULT.py.

4-bit unsigned array multiplier.

### __init__

```__init__(
a_bus,
b_bus,
product_bus
)
```

Construct a new 4-bit unsigned multiplier.

#### Args:

• `a_bus`: An object of type `Bus4`. The multiplicand. `a_bus` and `a_bus` are the most and least significant bit, respectively.
• `b_bus`: An object of type `Bus4`. The multiplier. `b_bus` and `b_bus` are the most and least significant bit, respectively.
• `product_bus`: An object of type `Bus8`. The product. `product_bus` and `product_bus` are the most and least significant bit, respectively.

#### Raises:

• `TypeError`: If either `a_bus` or `b_bus` is not a bus of width 4, or if `product_bus` is not a bus of width 8.

### __str__

Print out the wire values of the 4-bit unsigned multiplier.

```a_bus: (0, 0, 0, 0)
b_bus: (0, 0, 0, 0)
product_bus: (0, 0, 0, 0, 0, 0, 0, 0)
```

### __call__

```__call__(
a_bus=None,
b_bus=None,
product_bus=None
)
```

Force specific values on the wires of the 4-bit unsigned multiplier.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.

## Multiplier8

### Class `bw.arithmetic.Multiplier8` Defined in bitwise/arithmetic/MULT.py.

8-bit unsigned array multiplier.

### __init__

```__init__(
a_bus,
b_bus,
product_bus
)
```

Construct a new 8-bit unsigned multiplier.

#### Args:

• `a_bus`: An object of type `Bus8`. The multiplicand. `a_bus` and `a_bus` are the most and least significant bit, respectively.
• `b_bus`: An object of type `Bus8`. The multiplier. `b_bus` and `b_bus` are the most and least significant bit, respectively.
• `product_bus`: An object of type `Bus16`. The product. `product_bus` and `product_bus` are the most and least significant bit, respectively.

#### Raises:

• `TypeError`: If either `a_bus` or `b_bus` is not a bus of width 8, or if `product_bus` is not a bus of width 16.

### __str__

Print out the wire values of the 16-bit unsigned multiplier.

```a_bus: (0, 0, 0, 0, 0, 0, 0, 0)
b_bus: (0, 0, 0, 0, 0, 0, 0, 0)
product_bus: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
```

### __call__

```__call__(
a_bus=None,
b_bus=None,
product_bus=None
)
```

Force specific values on the wires of the 16-bit unsigned multiplier.

Note that this method takes zero positional arguments; all values must be given as keyword arguments.