This test belongs to this thread. Those who are interested what it's about may have a look there.
This is using the Advanced Editor
VC++ -> forum
File -> Notepad++ -> forumCode:#include "stdafx.h" #include <iostream> using namespace std; int setIndexFromBitValue(int allBits, int bitMask) { if (allBits & bitMask) return 2; // Bit is set: index is 2 else return 1; // Bit is not set: index is 1 } int _tmain(int argc, _TCHAR* argv[]) { int i; // our counter for (i=0 /* binary 000 */; i<=7 /* binary 111 */; ++i) // enumerate all possible bit combinations cout << "A" << setIndexFromBitValue(i, 4) // A is bit 2, binary mask is 100 << ", B" << setIndexFromBitValue(i, 2) // B is bit 1, binary mask 010 << ", C" << setIndexFromBitValue(i, 1) // C is bit 0, binary mask 001 << endl; return 0; }
VC++ -> Notepad++ -> forumCode:#include "stdafx.h" #include <iostream> using namespace std; int setIndexFromBitValue(int allBits, int bitMask) { if (allBits & bitMask) return 2; // Bit is set: index is 2 else return 1; // Bit is not set: index is 1 } int _tmain(int argc, _TCHAR* argv[]) { int i; // our counter for (i=0 /* binary 000 */; i<=7 /* binary 111 */; ++i) // enumerate all possible bit combinations cout << "A" << setIndexFromBitValue(i, 4) // A is bit 2, binary mask is 100 << ", B" << setIndexFromBitValue(i, 2) // B is bit 1, binary mask 010 << ", C" << setIndexFromBitValue(i, 1) // C is bit 0, binary mask 001 << endl; return 0; }
Code:#include "stdafx.h" #include <iostream> using namespace std; int setIndexFromBitValue(int allBits, int bitMask) { if (allBits & bitMask) return 2; // Bit is set: index is 2 else return 1; // Bit is not set: index is 1 } int _tmain(int argc, _TCHAR* argv[]) { int i; // our counter for (i=0 /* binary 000 */; i<=7 /* binary 111 */; ++i) // enumerate all possible bit combinations cout << "A" << setIndexFromBitValue(i, 4) // A is bit 2, binary mask is 100 << ", B" << setIndexFromBitValue(i, 2) // B is bit 1, binary mask 010 << ", C" << setIndexFromBitValue(i, 1) // C is bit 0, binary mask 001 << endl; return 0; }




Reply With Quote