Operator CastBitWidth

Operator Library: Base

The CastBitWidth operator changes the bit width by selecting the lower bits of the input. If the output bit width is greater than the input bit width, the value is kept, i.e. bits are added to the most significant bits. A sign extension is performed for signed value. If the output bit width is less than the input bit width, the most significant bits are discarded. The value changes to

,i.e. only the remaining bits are used. The output bit width is defined by .

For color values, each component is processed individually.

[Note] The CastBitWidth Operator Might Destroy Your Values

Only discard bits, if you know you will not need them. The CastBitWidth operator might destroy your values.

Input Bit Width Input Value Arithmetic Output Bit Width Output Value Comment
Decimal Binary Decimal Binary
5 10 01010 unsigned 4 10 1010 value is kept
5 10 01010 unsigned 3 2 010 value is changed
5 10 01010 signed 6 10 001010 value is kept
5 -10 10110 signed 6 -10 110110 value is kept, sign extension
5 10 01010 signed 4 -6 1010 value is changed
5 -10 10110 signed 4 6 0110 value is changed

Table 29. Examples


I/O Properties

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

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

The range of the input bit width is:

  • For unsigned inputs: [1, 64]

  • For signed inputs: [2, 64]

  • For unsigned color inputs: [3, 63]

  • For signed color inputs: [6, 63].

2

The range of the input bit width is:

  • For unsigned inputs: [1, 64]

  • For signed inputs: [2, 64]

  • For unsigned color inputs: [3, 63]

  • For signed color inputs: [6, 63].

Parameters

None

Examples of Use

The use of operator CastBitWidth is shown in the following examples: