CastBitWidth 運算子

Operator Library: Base

CastBitWidth 運算子透過選取輸入的低位元來變更 Bit Width。 如果輸出的 Bit Width 大於輸入的 Bit Width,則會保留數值,也就是會在最高有效位元 (most significant bits) 補位。 對於有號數 (signed value) 會執行符號擴展 (sign extension)。 如果輸出的 Bit Width 小於輸入的 Bit Width,則會捨棄最高有效位元。數值會變更為

,亦即僅使用剩餘的位元。輸出的 Bit Width 定義為 .

針對色彩數值,每個元件皆會個別處理。

[注意] CastBitWidth 運算子可能會破壞您的數值

唯有在確定不需要這些位元時,才捨棄位元。 CastBitWidth 運算子可能會破壞您的數值。

輸入 Bit Width 輸入值 Arithmetic 輸出 Bit Width 輸出值 備註
十進位 二進位 十進位 二進位
5 10 01010 無號數 4 10 1010 保留數值
5 10 01010 無號數 3 2 010 數值已變更
5 10 01010 有號 6 10 001010 保留數值
5 -10 10110 有號 6 -10 110110 保留數值,符號擴展
5 10 01010 有號 4 -6 1010 數值已變更
5 -10 10110 有號 4 6 0110 數值已變更

表 31. 範例


I/O Properties

Property Value
Operator Type O
Input Link I,資料輸入
Output Link O,資料輸出

Supported Link Format

Link Parameter Input Link I Output Link O
Bit Width [1, 64]1 [1, 64]2
Arithmetic {unsigned, signed} as I
Parallelism any as I
Kernel Columns any as I
Kernel Rows any as I
Img Protocol {VALT_IMAGE2D, VALT_LINE1D, VALT_PIXEL0D, VALT_SIGNAL} as I
Color Format any as I
Color Flavor any as I
Max. Img Width any as I
Max. Img Height any as I

1

輸入 Bit Width 的範圍為:

  • 針對無號輸入:[1, 64]

  • 對於有號數值:[2, 64]

  • 對於無號彩色輸入:[3, 63]

  • 針對有號色彩輸入:[6, 63]。

2

輸入 Bit Width 的範圍為:

  • 針對無號輸入:[1, 64]

  • 對於有號數值:[2, 64]

  • 對於無號彩色輸入:[3, 63]

  • 針對有號色彩輸入:[6, 63]。

Parameters

無

Examples of Use

以下範例顯示了 CastBitWidth 運算子的使用方式: