Edytuj

Udostępnij za pośrednictwem


BitHelper.SetFlag Method

Definition

Overloads

SetFlag(UInt32, Int32, Boolean)

Sets a bit to a specified value.

SetFlag(UInt32, Int32, Boolean)

Sets a bit to a specified value.

SetFlag(UInt64, Int32, Boolean)

Sets a bit to a specified value.

SetFlag(UInt64, Int32, Boolean)

Sets a bit to a specified value.

SetFlag(UInt32, Int32, Boolean)

Sets a bit to a specified value.

public static uint SetFlag (uint value, int n, bool flag);
static member SetFlag : uint32 * int * bool -> uint32
Public Shared Function SetFlag (value As UInteger, n As Integer, flag As Boolean) As UInteger

Parameters

value
UInt32

The input UInt32 value.

n
Int32

The position of the bit to set or clear (in [0, 31] range).

flag
Boolean

The value to assign to the target bit.

Returns

An UInt32 value equal to value except for the n-th bit.

Remarks

Just like HasFlag(UInt32, Int32), this method doesn't validate n and does not contain branching instructions, so it's well suited for use in tight loops as well.

Applies to

SetFlag(UInt32, Int32, Boolean)

Sets a bit to a specified value.

public static void SetFlag (ref uint value, int n, bool flag);
static member SetFlag : uint32 * int * bool -> unit
Public Shared Sub SetFlag (ByRef value As UInteger, n As Integer, flag As Boolean)

Parameters

value
UInt32

The target UInt32 value.

n
Int32

The position of the bit to set or clear (in [0, 31] range).

flag
Boolean

The value to assign to the target bit.

Remarks

Just like HasFlag(UInt32, Int32), this method doesn't validate n and does not contain branching instructions, so it's well suited for use in tight loops as well.

Applies to

SetFlag(UInt64, Int32, Boolean)

Sets a bit to a specified value.

public static ulong SetFlag (ulong value, int n, bool flag);
static member SetFlag : uint64 * int * bool -> uint64
Public Shared Function SetFlag (value As ULong, n As Integer, flag As Boolean) As ULong

Parameters

value
UInt64

The input UInt64 value.

n
Int32

The position of the bit to set or clear (in [0, 63] range).

flag
Boolean

The value to assign to the target bit.

Returns

An UInt64 value equal to value except for the n-th bit.

Remarks

Just like HasFlag(UInt64, Int32), this method doesn't validate n and does not contain branching instructions, so it's well suited for use in tight loops as well.

Applies to

SetFlag(UInt64, Int32, Boolean)

Sets a bit to a specified value.

public static void SetFlag (ref ulong value, int n, bool flag);
static member SetFlag : uint64 * int * bool -> unit
Public Shared Sub SetFlag (ByRef value As ULong, n As Integer, flag As Boolean)

Parameters

value
UInt64

The target UInt64 value.

n
Int32

The position of the bit to set or clear (in [0, 63] range).

flag
Boolean

The value to assign to the target bit.

Remarks

Just like HasFlag(UInt64, Int32), this method doesn't validate n and does not contain branching instructions, so it's well suited for use in tight loops as well.

Applies to