DWITE Online Computer Programming Contest

Binary Equipment

May 2010
Problem 1

In some games, the character equipment is fairly basic – one either has a particular type of item equipped, or not (“a shield is equipped”). A single bit is enough to hold this information, but memory is allocated and accessed in larger chunks. A single character, 1 byte in size, holds enough space for any configuration of 8 such binary equips (because 8 bits are in a 1 byte).

The input file DATA1.txt will contain 5 lines. Each line has an integer 0 ≤ EQUIPPED ≤ 255, a single space delimiter, and an integer 0 ≤ ITEM ≤ 7. ITEM is the position of the bit, where 0 is the least significant bit and 7 is the most significant bit.

The output file OUT1.txt will contain 5 lines of output, corresponding to each case of input: 1 if the item is present, 0 if not.

Reminder of how binary digits work: It’s all sums of powers of 2.

255 = 27 + 26 + 25 + 24 + 23 + 22 + 21 + 20 = 111111112.

Examples: Item 7 is represented by 27. Item 0 together with item 1 is represented as 20 + 21 = 000000112 = 3.

Sample Input:
0 0
1 0
1 1
2 1
255 7
Sample Output:
0
1
0
1
1