Function Bitwise Class

SetBitInStringFast

Set a bit within a binary string. Bits range from 1 (one is the least-significant-bit) to the number of bits in the value.

Signature (Visual Basic / VBA)

Public Function SetBitInStringFast( _
      ByVal vString As String _
    , ByRef vBit As Long _
    , ByRef vValue As Boolean _
    ) As String

Code Example

    SetBitInStringFast(Chr$(255) + Chr$(255), 3, 0) = Chr$(251) + Chr$(255)
    SetBitInStringFast(Chr$(0) + Chr$(0), 3, 1) = Chr$(4) + Chr$(0)

Parameters

Parameter Description
vString String in which one of the bits is to be set to either True or False.
vBit The number of the bit whose value within string vValue is to be changed.
vValue The value to which the specified bit will be set.

Notes & Version History

Note This function is different from GetBit and SetBit because this one considers the first string character to represent the LEAST-significant-byte instead of the MOST-significant-byte.
Note This function assumes that vBit represents one of the bits within the string vString and its behavior will be unpredictable if that is not true.
Note Function has restrictive argument types to avoid argument fix-up overhead.