DWITE '09 R7 #1 - Binary Equipment

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Problem type
DWITE Online Computer Programming Contest, 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 (8 bits in a 1 byte).

The input will contain 5 lines, each an integer 0 \le EQUIPPED \le 255, single space delimiter, and an integer 0 \le ITEM \le 7. ITEM is the position of the bit, where 0 is the least significant bit and 7 is the most significant bit.

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

Reminder of how binary digits work: it's all sums of powers of 2.

255 = 2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0 = 11111111

Where ITEM 7 is represented by 2^7; and ITEM 0 together with ITEM 1 are 2^0 + 2^1 = 00000011 = 3.

Sample Input

0 0
1 0
1 1
2 1
255 7

Sample Output

0
1
0
1
1

Problem Resource: DWITE

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments

There are no comments at the moment.