Skip to content
LIBRARY
Math.BooleanToInteger.md

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

Usage

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

Parameters:

NameDescriptionUnitsDefault value
integerTrueOutput signal for true Boolean input1
integerFalseOutput signal for false Boolean input0

Connectors

  • u - This connector represents a boolean signal as an input to a component (BooleanInput)

  • y - This connector represents an integer signal as an output from a component (IntegerOutput)

Behavior

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
Flattened 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
  "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

No test cases defined.