OMNI_SET_N_BIT
MACRO

OMNI_SET_N_BIT - Sets a bit in a value

SYNOPSIS top

A helper macro to set a specific bit within a value.

DESCRIPTION top

This is a helper macro designed to flip a bit within a numeric value and is defined as such:
#define OMNI_SET_N_BIT(val, n) val = (val | (1 << n))
It can be used as such:
short i = 2; // 0000 0000 0000 0010 (2)
char c = 65; // 0100 0001 (A)

// output: i = 2, c = a
std::cout << "i = " << i << ", c = " << c << std::endl;

OMNI_SET_N_BIT(c, 2);  // c is now 0100 0101 (69 == E)
OMNI_SET_N_BIT(i, 10); // i is now 0000 0100 0000 0010 (1026)

// output: i = 1026, c = E
std::cout << "i = " << i << ", c = " << c << std::endl;

CONSIDERATIONS top

No special considerations

PLATFORM SPECIFIC top

No platform specific notes.

NOTES top

None.