[Tutorial] Artificial Gouped Bool
#7

Some people does not understand the idea of manipulating and checking bits inside 32 bit variables.
You can use the macros below to manipulate and/or check for bits inside 32 bit variables.

pawn Code:
// Sets a single bit at a special position (0-31)
// Usage: set_bit(variable, position)
#define set_bit(%0,%1)  %0 |= 1<<(%1)

// Sets multiple bits related to the second argument
// Usage: set_bits(variable, value)
#define set_bits(%0,%1) %0 |= (%1)

// Unsets a single bit at a special position (0-31)
// Usage: unset_bit(variable, position)
#define unset_bit(%0,%1)    %0 &= ~(1<<(%1))

// Unsets multiple bits related to the second argument
// Usage: unset_bits(variable, value)
#define unset_bits(%0,%1)   %0 &= ~(%1)

// Toggles a single bit at a special position (0-31)
// Usage: toggle_bit(variable, position)
#define toggle_bit(%0,%1)   %0 ^= 1<<(%1)

// Toggles multiple bits related to the second argument
// Usage: toggle_bits(variable, value)
#define toggle_bits(%0,%1)  %0 ^= (%1)

// Returns true, if the bit at a special position (0-31) is enabled otherwise false
// Usage: is_bit(value, position)
#define is_bit(%0,%1)   (!!((%0)&(1<<(%1))))

// Returns true, if ONLY the bit at a special position (0-31) is enabled otherwise false
// Usage: is_only_bit(value, position)
#define is_only_bit(%0,%1)  ((%0) == (1<<(%1)))

// Returns true, if the bits related to the second argument are enabled otherwise false
// Usage: are_bits(value, value_2)
#define are_bits(%0,%1)     (((%0)&(%1)) == (%1))

// Returns true, if ONLY the bits related to the second argument are enabled otherwise false
// Usage: are_only_bits(value, value_2)
#define are_only_bits(%0,%1)    ((%0) == (%1))

// Returns true, if the bit at a special position (0-31) is disabled otherwise false
// Usage: isnot_bit(value, position)
#define isnot_bit(%0,%1)    (!((%0)&(1<<(%1))))

// Returns true, if the bits related to the second argument are disabled otherwise false
// Usage: arenot_bits(value, value_2)
#define arenot_bits(%0,%1)  (((%0)&(%1)) == 0)

// Returns true, if ONLY the bits related to the second argument are disabled otherwise false
// Usage: arenot_only_bits(value, value_2)
#define arenot_only_bits(%0,%1) ((~(%0)) == (%1))
Reply


Messages In This Thread
Artificial Gouped Bool - by Yashas - 20.04.2013, 03:33
Re: Artificial Gouped Bool - by K3 - 20.04.2013, 04:41
Re: Artificial Gouped Bool - by Dan.. - 20.04.2013, 05:16
Re: Artificial Gouped Bool - by mastermax7777 - 20.04.2013, 05:29
Re: Artificial Gouped Bool - by Dan.. - 20.04.2013, 05:35
Re: Artificial Gouped Bool - by mastermax7777 - 20.04.2013, 05:45
AW: Artificial Gouped Bool - by BigETI - 20.04.2013, 06:58
Re: Artificial Gouped Bool - by Yashas - 20.04.2013, 11:14

Forum Jump:


Users browsing this thread: 1 Guest(s)