Use this function to return the result after setting the specified bit on in a value.
The parameters specify the numeric value and the bit position on which the operation is performed. The specified bit is set to a 1 in the value provided. If the bit was already on, the value is unchanged. Specifying a negative or zero bit position does not result in any change to the value.
Note that integer values have 32 bits. When looking at the value in binary form, bit 1 is on the left and bit 32 is on the right.
Bit 32 -->0000 0000 0000 0000 0000 0000 0000 0000<-- Bit 1
Here is an example:
y = 6 (6 is 0110 in binary)
z = BitSet(x,1)
z = 7 (7 is 0111 in binary)
y = 6 (6 is 0110 in binary)
z = BitSet(x,4)
z = 15 (15 is 1110 in binary)
© Copyright 2017, Oracle and/or its affiliates. All rights reserved. Legal Notices