A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C# program to demonstrate the bitwise operations
Q:

C# program to demonstrate the bitwise operations

0

C# program to demonstrate the bitwise operations

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the bitwise operations is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the bitwise operations.

using System;

class Bitwise
{
    public static void Main()
    {
        byte num1   = 10;
        byte num2   = 2;
        byte result = 0;

        result  =  (byte)(num1 & num2);
        Console.WriteLine("{0} & {1} = {2}",num1,num2, result);

        result = (byte)(num1 | num2);
        Console.WriteLine("{0} | {1} = {2}", num1, num2, result);

        result = (byte)(num1 ^ num2);
        Console.WriteLine("{0} ^ {1} = {2}", num1, num2, result);
    }
}

Output:

10 & 2 = 2
10 | 2 = 10
10 ^ 2 = 8
Press any key to continue . . .

Explanation:

Here, we created a class Bitwise that contains the Main() method. Here, we declared three variables of byte type that are initialized with 10, 2, and 0 respectively.

result  =  (byte)(num1 & num2);
Console.WriteLine("{0} & {1} = {2}",num1,num2, result);

result = (byte)(num1 | num2);
Console.WriteLine("{0} | {1} = {2}", num1, num2, result);

In the above code, we performed the bitwise AND, bitwise OR, and bitwise XOR operations and printed the result on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now