CSHARP
C# Bitwise Right Shift
using System;
namespace Operator
{
class LeftShift
{
public static void Main(string[] args)
{
int number = 42;
Console.WriteLine("{0}>>1 = {1}", number, number>>1);
Console.WriteLine("{0}>>2 = {1}", number, number>>2);
Console.WriteLine("{0}>>4 = {1}", number, number>>4);
}
}
}
Bitwise Left Shift C#
using System;
namespace Operator
{
class LeftShift
{
public static void Main(string[] args)
{
int number = 42;
Console.WriteLine("{0}<<1 = {1}", number, number<<1);
Console.WriteLine("{0}<<2 = {1}", number, number<<2);
Console.WriteLine("{0}<<4 = {1}", number, number<<4);
}
}
}
C# Bitwise and Bit Shift Operator
using System;
namespace Operator
{
class BitOperator
{
public static void Main(string[] args)
{
int firstNumber = 10;
int secondNumber = 20;
int result;
result = ~firstNumber;
Console.WriteLine("~{0} = {1}", firstNumber, result);
result = firstNumber & secondNumber;
Console.WriteLine("{0} & {1} = {2}", firstNumber,secondNumber, result);
result = firstNumber | secondNumber;
Console.WriteLine("{0} | {1} = {2}", firstNumber,secondNumber, result);
result = firstNumber ^ secondNumber;
Console.WriteLine("{0} ^ {1} = {2}", firstNumber,secondNumber, result);
result = firstNumber << 2;
Console.WriteLine("{0} << 2 = {1}", firstNumber, result);
result = firstNumber >> 2;
Console.WriteLine("{0} >> 2 = {1}", firstNumber, result);
}
}
}
C# Bitwise Right Shift
using System;
namespace Operator
{
class LeftShift
{
public static void Main(string[] args)
{
int number = 42;
Console.WriteLine("{0}>>1 = {1}", number, number>>1);
Console.WriteLine("{0}>>2 = {1}", number, number>>2);
Console.WriteLine("{0}>>4 = {1}", number, number>>4);
}
}
}
Bitwise Left Shift C#
using System;
namespace Operator
{
class LeftShift
{
public static void Main(string[] args)
{
int number = 42;
Console.WriteLine("{0}<<1 = {1}", number, number<<1);
Console.WriteLine("{0}<<2 = {1}", number, number<<2);
Console.WriteLine("{0}<<4 = {1}", number, number<<4);
}
}
}
C# Bitwise and Bit Shift Operator
using System;
namespace Operator
{
class BitOperator
{
public static void Main(string[] args)
{
int firstNumber = 10;
int secondNumber = 20;
int result;
result = ~firstNumber;
Console.WriteLine("~{0} = {1}", firstNumber, result);
result = firstNumber & secondNumber;
Console.WriteLine("{0} & {1} = {2}", firstNumber,secondNumber, result);
result = firstNumber | secondNumber;
Console.WriteLine("{0} | {1} = {2}", firstNumber,secondNumber, result);
result = firstNumber ^ secondNumber;
Console.WriteLine("{0} ^ {1} = {2}", firstNumber,secondNumber, result);
result = firstNumber << 2;
Console.WriteLine("{0} << 2 = {1}", firstNumber, result);
result = firstNumber >> 2;
Console.WriteLine("{0} >> 2 = {1}", firstNumber, result);
}
}
}