This page is still under construction.

Parts of this page are still being built. What you see may change.

Bitwise Operations on Binary Numbers

Time limit2sMemory limit512 MB

Summary
Given two equal-length binary strings, output their bitwise AND, OR, XOR, and the complemented forms of each, keeping length and leading zeros.
Level

Easy2 of 10

Topics
String, Bit manipulation, Implementation
Solved
No attempts yet

Problem

You are given two binary numbers A and B of the same length. Compute the five bitwise results A & B, A | B, A ^ B, ~A, and ~B.

Every operation is applied position by position. A bit of & is 1 only when both bits at that position are 1. A bit of | is 1 when at least one of them is 1. A bit of ^ is 1 when the two bits differ. ~ turns each 0 into 1 and each 1 into 0.

Each result is a binary number of the same length as the input, and its leading zeros stay in place.

Input

The first line has the binary number A and the second line has the binary number B. The two numbers have the same length LL, where 1≤L≤1000001 \le L \le 100000.

Output

Print five lines. Print A & B on the first line, A | B on the second, A ^ B on the third, ~A on the fourth, and ~B on the fifth. Each line is a binary number of length LL, with leading zeros kept.

Examples2

  1. Example 1

    Input
    0001011000
    0000101111
    
    Expected output
    0000001000
    0001111111
    0001110111
    1110100111
    1111010000
    
  2. Example 2

    Input
    0
    0
    
    Expected output
    0
    0
    0
    1
    1