BitwiseSetBit

Description

Allows you to set the bit at a specified position of a binary number.

Syntax

BitwiseSetBit ( val1, bit_position)

Argument

Description

val

Unsigned long for the binary number in which you want to set a particular bit

bit_position

Unsigned integer for the bit, from 1 to 32, that you want to set

Returns

UnsignedLong. Returns the result for a binary number when a bit at the position specified by bit_Position is turned on. If one of its arguments is null, BitwiseSetBit returns null.

Usage

In PocketBuilder there are 32 bits in an unsigned long. If the value of bit_Position is 0, or greater than 32, PocketBuilder fires the runtime SystemError event because the value is out of range.

Examples

Example 1

This example sets the bit in the third position of the testValue variable.

UnsignedLong ll_result

ll_result = BitwiseSetBit(testValue, 3)

In this example, if testValue is 10, with bits in the second and fourth positions, the return value is a binary number with bits set at the second, third, and fourth positions. This converts to a decimal value of 14.

If testValue is 12, it has bits set in the third and fourth positions. In this case, calling BitwiseSetBit with a bit_position value of 3 does not change the original value, since it already has a set bit at its third position.

See also