SetBit

From GECK
Jump to: navigation, search


A function added by the New Vegas Script Extender.

Description

Returns the specified Int with the specified bit set to 1, or optionally 0 (cleared). This function is useful for manipulating bitmasks.

Syntax

[help]
(int) SetBit Target:int BitToSet:int NewBitValue:bool 

Example

int a
set a to 11		; bits 0, 1, 3 set ; %00001011 binary
set a to SetBit a, 2	; sets bit 2 (value 4) ; %00000100 binary
; a is now 15
set a to SetBit a, 1, 0	; would set bit 1 (value 2), but the third parameter is 0 so instead it clears the bit
; a is now 13

Notes

  • SetBit considers the first bit be numbered, 0, and the final bit to be 31; however, it should not be used to change bits greater than 29 to avoid sign and float conversion issues.

See Also