Bitwise Operations on Binary Numbers
Time limit2sMemory limit512 MB
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 , where .
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 , with leading zeros kept.