0% found this document useful (0 votes)
16 views

Using System

The document defines a BitwiseCalculator program that takes in two integers from the user, allows the user to select a bitwise operation to perform on those integers, and displays the result. It creates classes for the different bitwise operations - BitwiseAND, BitwiseOR, BitwiseXOR, and BitwiseNOT - that each perform the operation and return the result.

Uploaded by

Kyla Barribal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Using System

The document defines a BitwiseCalculator program that takes in two integers from the user, allows the user to select a bitwise operation to perform on those integers, and displays the result. It creates classes for the different bitwise operations - BitwiseAND, BitwiseOR, BitwiseXOR, and BitwiseNOT - that each perform the operation and return the result.

Uploaded by

Kyla Barribal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

class BitwiseCalculator
{
static void Main()
{
Console.WriteLine("Bitwise Calculator");

Console.Write("Enter the first integer: ");


int num1 = int.Parse(Console.ReadLine());

Console.Write("Enter the second integer: ");


int num2 = int.Parse(Console.ReadLine());

Console.WriteLine("\nBitwise Operations:");
Console.WriteLine("1. & (AND)");
Console.WriteLine("2. | (OR)");
Console.WriteLine("3. ^ (XOR)");
Console.WriteLine("4. ~ (NOT)");
Console.Write("Enter the symbol of the bitwise operation: ");
int choice = int.Parse(Console.ReadLine());

switch (select)
{
case "&":
break;
case "|":
break;
case "^":
break;
case "~":
break;

BitwiseOperation operation;

switch (choice)
{
case 1:
operation = new BitwiseAND(num1, num2);
break;
case 2:
operation = new BitwiseOR(num1, num2);
break;
case 3:
operation = new BitwiseXOR(num1, num2);
break;
case 4:
operation = new BitwiseNOT(num1);
break;
default:
Console.WriteLine("Invalid choice");
return;
}

Console.WriteLine($"Result of {operation.GetOperationName()}:
{operation.GetResult()}");
}
}

abstract class BitwiseOperation


{
protected readonly int num1;
protected readonly int num2;

public BitwiseOperation(int num1, int num2 = 0)


{
this.num1 = num1;
this.num2 = num2;
}

public abstract string GetOperationName();


public abstract int GetResult();
}

class BitwiseAND : BitwiseOperation


{
public BitwiseAND(int num1, int num2) : base(num1, num2) { }

public override string GetOperationName()


{
return "AND";
}

public override int GetResult()


{
return num1 & num2;
}
}

class BitwiseOR : BitwiseOperation


{
public BitwiseOR(int num1, int num2) : base(num1, num2) { }

public override string GetOperationName()


{
return "OR";
}

public override int GetResult()


{
return num1 | num2;
}
}

class BitwiseXOR : BitwiseOperation


{
public BitwiseXOR(int num1, int num2) : base(num1, num2) { }

public override string GetOperationName()


{
return "XOR";
}

public override int GetResult()


{
return num1 ^ num2;
}
}

class BitwiseNOT : BitwiseOperation


{
public BitwiseNOT(int num1) : base(num1) { }

public override string GetOperationName()


{
return "NOT";
}

public override int GetResult()


{
return ~num1;
}
}

You might also like