SAMPLE PMT, F'06

----------------

 

In this task you are to code three elements: two binary operators and a binary to decimal converter.  The input will be pairs of binary numbers and an operator.  The output will be the decimal number generated by applying the binary operator to the two input numbers.

 

The input consists of a single digit on a line by itself indicating the number of inputs in the file.  This is followed by one input per line.

Each input consists of an operator (either the | or & character)

followed by a space, followed by the first binary number, a space, and the second binary number.

 

The output should consist of one line per input.  The output should

contain the first binary number, a space, the operator, a space, the

second binary number, a space, the '=' character, a space and finally

the decimal equivalent of the result.

 

All input should be on standard input and all output should go to

standard output.

 

 

SAMPLE INPUT:

5

& 10 01

| 10 01

& 1111 0101

| 1111 0101

| 01010101010101 10101010101010

 

 

SAMPLE OUTPUT:

10 & 01 = 0

10 | 01 = 3

1111 & 0101 = 5

1111 | 0101 = 15

01010101010101 | 10101010101010 = 16383

 

 

IMPLEMENTATION NOTES:

Here are the first few lines of output explained:

 

* 10 & 01 = 0

  In order for & to produce a 1, both strings must have a 1 in the same

  position. The result is binary 00, which converts to decimal 0.

 

* 10 | 01 = 3

  The | operator will produce a 1 when either string has a 1 in the same

  position.  The result is binary 11, which converts to decimal 3.

 

* 1111 & 0101 = 5

  The & ends up producing binary 0101, which converts to decimal 5.

 

* 1111 | 0101 = 15

  The or ends up producing binary 1111, which converts to decimal 15.

 

The binary to decimal conversion is really simple - you just have to

count from the right end of the string - the 1st position is 2^0 = 1,

the second is 2^1 = 2, the third is 2^2 = 4, the fourth is 2^3 = 8 and

so on down the line.

 

In the third example above, the binary result is 0101. The conversion of

this binary number to a decimal number would look like this:

 

  binary 0101 = decimal 0 + 2^2 + 0 + 2^0 = 0+4+0+1 = 5

 

The conversion of binary 1111 in the fourth example to decimal would

look like this:

 

  binary 1111 = decimal 2^3 + 2^2 + 2^1 + 2^0 = 8+4+2+1 = 15