Function: SetB
- Updated2024-09-12
- 3 minute(s) read
Function: SetB
Function: SetB
Sets a specific bit in the binary representation of a decimal number. The SetB function converts a decimal number to a binary number, sets the specified bit, and reconverts the new binary number to a decimal number.
ReturnValue = SetB(Value,BitIndex)
Input Parameters
Value | Specifies a numeric value, a variable, or a data channel. |
BitIndex | Specifies a numeric value, a variable, or a data channel for the index of the bit you want to check. Value range 0 to 31 |
![]() | Note If you enter numbers with decimal places for the parameters Value and BitIndex, DIAdem rounds the numbers to integers. From DIAdem 2014, the function no longer calculates the sum of the BitIndex input parameter. |
Return Parameters
ReturnValue | Returns integer values. If the indexed bit is already set, which means it has the value 1, its value remains 1. If the input value is NoValue, the SetB function returns the value NoValue. If the input parameter BitIndex is outside the value range, the function returns the value of the input parameter Value. |
Examples
The following example sets the seventh bit in the binary representation of the decimal number 10.
VBScript | Python |
Dim intMyResult intMyResult = SetB(10,6) 'intMyResult = 74
The following example sets the bits, indexed by the Group1/Reference data channel, of the values in the Group1/Input data channel, and saves the new decimal numbers in the new data channel Group2/Result. DIAdem skips values of the Group1/Reference index channel that are higher than 31.
VBScript | Python |
Call Calculate ("Ch(""Group2/Result"")= SetB (Ch(""Group1/Input""),Ch(""Group1/Reference""))")
![]() | Note You must use the Calculate command in scripts to calculate data channels with formulas. Compute the data channels according to the syntax in the Calculator. Refer to the procedures Executing Channel Calculations in the Calculator and Assigning a Value to a Variable in the Calculator for more information about the Calculator. |
![]() |
The first physical input quantity is arbitrary. The second input quantity must be dimensionless. The first physical input quantity and the result quantity are the same. The Input and Result Quantities for Quantity-Based Calculations page contains an overview of the input quantities and result quantities of all functions. Refer to the Help page Calculating Quantity-Based and Non-Quantity-Based in DIAdem for the conditions and rules for quantity-based calculations. |
Related Functions
Function: AndB | Function: ClrB | Function: GetB | Function: NotB | Function: OrB | Function: ShL | Function: ShR | Function: XOrB | Variable: ApplicationLegacyBinaryOperations