Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BitwiseOperators {
- public static void Main(string[] args) {
- if (args.Length < 2) {
- Console.Error.WriteLine("Usage: [filename] <first_number> <second_number>");
- Environment.Exit(1);
- }
- int a = Int32.Parse(args[0]), b = Int32.Parse(args[1]);
- Console.WriteLine("OR: {0} | {1} = {2}", a.ToString(), b.ToString(), (a | b).ToString());
- Console.WriteLine("AND: {0} & {1} = {2}", a.ToString(), b.ToString(), (a & b).ToString());
- Console.WriteLine("XOR: {0} ^ {1} = {2}", a.ToString(), b.ToString(), (a ^ b).ToString());
- Console.WriteLine("Left shift: {0} << {1} = {2}", a.ToString(), b.ToString(), (a << b).ToString());
- Console.WriteLine("Right shift: {0} >> {1} = {2}", a.ToString(), b.ToString(), (a >> b).ToString());
- Console.WriteLine("1's complement: ~{0} = {1}", a.ToString(), (~a).ToString());
- }
- }
- /*
- $ ./bitwise.exe 2 3
- OR: 2 | 3 = 3
- AND: 2 & 3 = 2
- XOR: 2 ^ 3 = 1
- Left shift: 2 << 3 = 16
- Right shift: 2 >> 3 = 0
- 1's complement: ~2 = -3
- */
Add Comment
Please, Sign In to add comment