int ConvertValuetoBitmaskOffset(int input) { int offset = 0; for (int a = 0; a < sizeof (int)*8; a++) { offset = 1 << a; if (input == offset) return a; } return 0; }