DataTypeConversion_to_UInt8 DataTypeConversion_to_UInt8 Icon

WIP.DataTypeConversion_to_UInt8

DataTypeConversion_to_UInt8(; saturate_on_overflow=false)

Converts a real-valued input signal into an 8-bit unsigned integer (UInt8).

Parameters

  • saturate_on_overflow: When enabled, clamps output to 0–255 (saturation). When disabled, values wrap around using modulo arithmetic (default: false)

Variables

  • u(t): Real-valued input signal
  • y(t): 8-bit unsigned integer output (0–255)

Description

Converts input to UInt8 with floor rounding (fractional values rounded toward negative infinity). When saturateonoverflow is true, values outside 0–255 are clamped. When false, values wrap around. This block mimics Simulink's Data Type Conversion behavior when configured for 8-bit unsigned integers with Floor rounding.

Examples

to_uint8_floor(42.7, true)     → 42
to_uint8_floor(260.7, true)    → 255  (saturated)
to_uint8_floor(260.7, false)   → 4    (wrapped)
to_uint8_floor(-3.2, true)     → 0    (saturated)
to_uint8_floor(-3.2, false)    → 252  (wrapped)

Usage

PrimitiveComponents.WIP.DataTypeConversion_to_UInt8(saturate_on_overflow=false)

Parameters:

NameDescriptionUnitsDefault value
saturate_on_overflowfalse

Connectors

  • u - This connector represents a real signal as an input to a component (RealInput)
  • y - This connector represents an integer signal as an output from a component (IntegerOutput)

Behavior

\[ \begin{align} y\left( t \right) &= to\_uint8\_floor\left( u\left( t \right), \mathtt{saturate\_on\_overflow} \right) \end{align} \]

Source

"""
    DataTypeConversion_to_UInt8(; saturate_on_overflow=false)

Converts a real-valued input signal into an 8-bit unsigned integer (UInt8).

# Parameters
- `saturate_on_overflow`: When enabled, clamps output to 0–255 (saturation). When disabled, values wrap around using modulo arithmetic (default: false)

# Variables
- `u(t)`: Real-valued input signal
- `y(t)`: 8-bit unsigned integer output (0–255)

# Description
Converts input to UInt8 with floor rounding (fractional values rounded toward negative infinity).
When saturate_on_overflow is true, values outside 0–255 are clamped. When false, values wrap around.
This block mimics Simulink's Data Type Conversion behavior when configured for 8-bit unsigned integers with Floor rounding.

# Examples

touint8floor(42.7, true) → 42 touint8floor(260.7, true) → 255 (saturated) touint8floor(260.7, false) → 4 (wrapped) touint8floor(-3.2, true) → 0 (saturated) touint8floor(-3.2, false) → 252 (wrapped)

"""</span>
<span class="hljs-keyword">component</span> DataTypeConversion_to_UInt8
&nbsp;&nbsp;<span class="hljs-symbol">u</span> = <span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/connectors/RealInput.html">RealInput</a></span>() {
&nbsp;&nbsp;&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"placement": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"diagram": {"x1": -40, "x2": 0, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"icon": {"x1": -40, "x2": 0, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
&nbsp;&nbsp;<span class="hljs-symbol">y</span> = <span>Dyad.IntegerOutput</span>() {
&nbsp;&nbsp;&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"placement": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"diagram": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"icon": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
&nbsp;&nbsp;# Clamp to 0–255 if overflow occurs
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">saturate_on_overflow</span>::<span>Boolean</span> = false
<span class="hljs-keyword">relations</span>
&nbsp;&nbsp;y = to_uint8_floor(u, saturate_on_overflow)
<span class="hljs-keyword">metadata</span> {"Dyad": {"icons": {"default": "dyad://PrimitiveComponents/Convert.svg"}}}
<span class="hljs-keyword">end</span></code></pre>
Flattened Source
"""
    DataTypeConversion_to_UInt8(; saturate_on_overflow=false)

Converts a real-valued input signal into an 8-bit unsigned integer (UInt8).

# Parameters
- `saturate_on_overflow`: When enabled, clamps output to 0–255 (saturation). When disabled, values wrap around using modulo arithmetic (default: false)

# Variables
- `u(t)`: Real-valued input signal
- `y(t)`: 8-bit unsigned integer output (0–255)

# Description
Converts input to UInt8 with floor rounding (fractional values rounded toward negative infinity).
When saturate_on_overflow is true, values outside 0–255 are clamped. When false, values wrap around.
This block mimics Simulink's Data Type Conversion behavior when configured for 8-bit unsigned integers with Floor rounding.

# Examples

touint8floor(42.7, true) → 42 touint8floor(260.7, true) → 255 (saturated) touint8floor(260.7, false) → 4 (wrapped) touint8floor(-3.2, true) → 0 (saturated) touint8floor(-3.2, false) → 252 (wrapped)

"""</span>
<span class="hljs-keyword">component</span> DataTypeConversion_to_UInt8
&nbsp;&nbsp;<span class="hljs-symbol">u</span> = <span class="hljs-link"><a href="https://help.juliahub.com/dyad/dev/stdlib/Dyad/connectors/RealInput.html">RealInput</a></span>() {
&nbsp;&nbsp;&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"placement": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"diagram": {"x1": -40, "x2": 0, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"icon": {"x1": -40, "x2": 0, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
&nbsp;&nbsp;<span class="hljs-symbol">y</span> = <span>Dyad.IntegerOutput</span>() {
&nbsp;&nbsp;&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"placement": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"diagram": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"icon": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
&nbsp;&nbsp;# Clamp to 0–255 if overflow occurs
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">saturate_on_overflow</span>::<span>Boolean</span> = false
<span class="hljs-keyword">relations</span>
&nbsp;&nbsp;y = to_uint8_floor(u, saturate_on_overflow)
<span class="hljs-keyword">metadata</span> {"Dyad": {"icons": {"default": "dyad://PrimitiveComponents/Convert.svg"}}}
<span class="hljs-keyword">end</span></code></pre>


Test Cases

No test cases defined.

  • Examples
  • Experiments
  • Analyses