Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

set_bit

By Daniel · January 4, 2009

Returns a modified version of n with some specified bit set to val. bit=0 indicates the least significant bit (worth 1, usually written on the far right), bit=1 indicates the next (worth 2), and so forth; in general terms, bit=p refers to the bit worth 2^p.

See also: get_bit

/* set_bit(n, bit, val)
 *
 * Returns a modified version of n with some specified bit set to val. bit=0
 * indicates the least significant bit (worth 1, usually written on the far
 * right), bit=1 indicates the next (worth 2), and so forth; in general terms,
 * bit=p refers to the bit worth 2^p.
 */

if (argument2)
  return argument0 | (1 << argument1);
else
  return argument0 & (~0 - (1 << argument1));

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement