CastBitWidth Operator

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 運算子可能會破壞您的數值。

Input Bit Width Input Value Arithmetic Output Bit Width 輸出值 Comment
Decimal Binary Decimal Binary
5 10 01010 unsigned 4 10 1010 數值保持不變
5 10 01010 unsigned 3 2 010 數值已變更
5 10 01010 signed 6 10 001010 數值保持不變
5 -10 10110 signed 6 -10 110110 數值保持不變,進行符號擴展
5 10 01010 signed 4 -6 1010 數值已變更
5 -10 10110 signed 4 6 0110 數值已變更

表 31. 範例


I/O Properties

Property Value
Operator Type O
Input Link I, data input
Output Link O, data output

支援的 Link 格式

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]。

參數

無

使用範例

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