#include <iostream>

using std::size_t;
using std::cout;
using std::endl;

typedef unsigned short data_t;

// convention: bit # 0 is least significant

bool access_bit(data_t v, size_t i)
{
	return (v & (1 << i)) > 0;
}

data_t set_true(data_t v, size_t i)
{
	return v | (1 << i);
}

data_t set_false(data_t v, size_t i)
{
	return v ^ (v & (1 << i));
}

data_t flip(data_t v, size_t i)
{
	return v ^ (1 << i);
}

int main()
{
	data_t t = 1+4+16;
	
	for (int i = 0; i < 8*sizeof(data_t); ++i)
		cout << access_bit(t, i);
	cout << endl;
	// 1010100000000000
	
	t = set_true(t, 6);
	
	for (int i = 0; i < 8*sizeof(data_t); ++i)
		cout << access_bit(t, i);
	cout << endl;
	// 1010101000000000
	
	t = set_false(t, 0);
	t = set_false(t, 1);
	
	for (int i = 0; i < 8*sizeof(data_t); ++i)
		cout << access_bit(t, i);
	cout << endl;
	// 0010101000000000
	
	t = flip(t, 0);
	t = flip(t, 2);
	
	for (int i = 0; i < 8*sizeof(data_t); ++i)
		cout << access_bit(t, i);
	cout << endl;
	// 1000101000000000
}
