Skip to main content

BooleanToNumber

The BooleanToNumber operator converts BooleanData messages to NumberData messages. Each boolean value is mapped to a numeric equivalent: true becomes 1.0 and false becomes 0.0. Timestamps are preserved.

Configuration

Requires only an operator ID.

Ports

  • Input Port 0: Accepts BooleanData messages
  • Output Port 0: Emits NumberData messages

Example Operation

TimeInput Port 0 (Boolean)Output Port 0 (Number)
1true1.0
2false0.0
3true1.0
5false0.0
7true1.0

Behavior

The BooleanToNumber operator:

  • Maintains message order
  • Preserves timestamps
  • Does not buffer messages
  • Has constant 1:1 throughput
  • Maps true to 1.0 and false to 0.0

Mathematical representation: y(tn)={1.0if x(tn)=true0.0if x(tn)=falsey(t_n) = \begin{cases} 1.0 & \text{if } x(t_n) = \text{true} \\ 0.0 & \text{if } x(t_n) = \text{false} \end{cases}

Implementation

// Create operator
auto b2n = make_boolean_to_number("b2n1");

// Process boolean values
b2n->receive_data(create_message<BooleanData>(1, BooleanData{true}), 0);
b2n->receive_data(create_message<BooleanData>(2, BooleanData{false}), 0);
b2n->execute();

// Output will contain NumberData messages: 1.0 at time 1, 0.0 at time 2

Error Handling

Throws std::runtime_error if:

  • Receiving message with incorrect type
  • Receiving message on invalid port