---
url: /dyad/dev/stdlib/BlockComponents/components/Math.BooleanToInteger.md
description: Dyad Math.BooleanToInteger docs.  Convert Boolean to Integer signal.
---

# `Math.BooleanToInteger` {#Math.BooleanToInteger}

Convert Boolean to Integer signal.

This block computes the output `y` as Integer equivalent of the Boolean input `u`:

```
y = if u then integerTrue else integerFalse
```

where `u` is of Boolean and `y` of Integer type, and `integerTrue` and `integerFalse` are parameters.

This component extends from [`BlockComponents.Interfaces.PartialBooleanSI`](../types/Interfaces.PartialBooleanSI.md)

## Usage {#Usage}

`BlockComponents.Math.BooleanToInteger(integerTrue=1, integerFalse=0)`

## Parameters: {#Parameters:}

|           Name |                           Description | Units | Default value |
| --------------:| -------------------------------------:| -----:| -------------:|
|  `integerTrue` |  Output signal for true Boolean input |     – |             1 |
| `integerFalse` | Output signal for false Boolean input |     – |             0 |

## Connectors {#Connectors}

* `u` - This connector represents a boolean signal as an input to a component ([`BooleanInput`](/stdlib/Dyad/connectors/BooleanInput#BooleanInput))

* `y` - This connector represents an integer signal as an output from a component ([`IntegerOutput`](/stdlib/Dyad/connectors/IntegerOutput#IntegerOutput))

## Behavior {#Behavior}

$$ \begin{align}
y\left( t \right) &= ifelse\left( u\left( t \right), \mathtt{integerTrue}, \mathtt{integerFalse} \right)
\end{align}
$$

## Source {#Source}

````dyad
"""
Convert Boolean to Integer signal.

This block computes the output `y` as Integer equivalent of the Boolean input `u`:

```
y = if u then integerTrue else integerFalse
```

where `u` is of Boolean and `y` of Integer type, and `integerTrue` and `integerFalse` are parameters.
"""
component BooleanToInteger
  extends BlockComponents.Interfaces.PartialBooleanSI
  "Connector of Integer output signal"
  y = IntegerOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Output signal for true Boolean input"
  parameter integerTrue::Integer = 1
  "Output signal for false Boolean input"
  parameter integerFalse::Integer = 0
relations
  y = ifelse(u, integerTrue, integerFalse)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/BooleanToInteger.svg"}
  }
}
end
````

````dyad
"""
Convert Boolean to Integer signal.

This block computes the output `y` as Integer equivalent of the Boolean input `u`:

```
y = if u then integerTrue else integerFalse
```

where `u` is of Boolean and `y` of Integer type, and `integerTrue` and `integerFalse` are parameters.
"""
component BooleanToInteger
  "Connector of Boolean input signal"
  u = BooleanInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 450, "x2": 0, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Connector of Integer output signal"
  y = IntegerOutput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Output signal for true Boolean input"
  parameter integerTrue::Integer = 1
  "Output signal for false Boolean input"
  parameter integerFalse::Integer = 0
relations
  y = ifelse(u, integerTrue, integerFalse)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/BooleanToInteger.svg"}
  }
}
end
````

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`BooleanToInteger`](Math.BooleanToInteger.md)

  * [`BooleanToInteger`](Math.BooleanToInteger.md)

  * [`Constant`](Math.BooleanToInteger.md)

  * [`RealToBoolean`](Math.BooleanToInteger.md)

  * [`Sine`](Math.BooleanToInteger.md)
