You can see from this example right sift operator keep the original size of the bits always the same but left shift operator adding bits to the original size of the bits thus increasing the size of total bits. Please explain the differences. Problem is highlighted.
using System;
class Program
{
static void Main()
{
int value1 = 10;//1010
int i = 1;
int shift = value1 >> i;
Console.WriteLine("{0}", shift);//0101=5
shift = value1 << i;
Console.WriteLine("\n{0}", shift);//10100=20
shift = value1 << 2;
Console.WriteLine("\n{0}", shift);//101000=40
shift = value1 >> 2;
Console.WriteLine("\n{0}", shift);//0010=2
Console.ReadKey();
}
}
Loading
Posted Sep 30, 2013, 4:34 AM
VulpesPosted Sep 30, 2013, 4:30 AM
Posted Sep 29, 2013, 3:47 PM
We use ………2^5 2^4 2^3 2^2 2^1 2^0 to find the value of the bits. I consider 2^0 as the dead end. When we use right sift operator there is no room for bits to move forward because 2^0 is a dead end therefore it drop existing bits and add new bits.
When we use left sift operator there is enough room for bits to move forward because 2^5 is not a dead end therefore without dropping existing bits, new bits can be added.
VulpesPosted Sep 29, 2013, 2:47 PM
However, they are still there.
For example, the binary integer 1010 has 28 zero bits in front of the 4 displayed. One of these is the 'sign' bit - 0 for a non-negative and 1 for a negative integer.