BoolExtensions.ToBitwiseMask32(Boolean) Method

Definition

Converts the given Boolean value to an Int32 mask with all bits representing the value of the input flag (either 0xFFFFFFFF or 0x00000000).

public static int ToBitwiseMask32 (this bool flag);
static member ToBitwiseMask32 : bool -> int
<Extension()>
Public Function ToBitwiseMask32 (flag As Boolean) As Integer

Parameters

flag
Boolean

The input value to convert.

Returns

0xFFFFFFFF if flag is true, 0x00000000 otherwise.

Remarks

This method does not contain branching instructions, and it is only guaranteed to work with Boolean values being either 0 or 1. Operations producing a Boolean result, such as numerical comparisons, always result in a valid value. If the Boolean value is produced by fields with a custom FieldOffsetAttribute, or by using As<T>(Object) or other unsafe APIs to directly manipulate the underlying data though, it is responsibility of the caller to ensure the validity of the provided value.

Applies to