Eri523
August 11th, 2010, 11:51 AM
This test belongs to this thread (http://www.codeguru.com/forum/showthread.php?t=501226). Those who are interested what it's about may have a look there.
This is using the Advanced Editor
VC++ -> forum
#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;
}
File -> Notepad++ -> forum
#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++ -> forum
#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;
}
This is using the Advanced Editor
VC++ -> forum
#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;
}
File -> Notepad++ -> forum
#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++ -> forum
#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;
}