This program is given in the following website. Please explain the meaning of the two chevron mark. Problem is highlighted.
http://www.dotnetperls.com/binary-representation
using System;
class Program
{
static void Main()
{
// Write full binary string for 100.
Console.WriteLine(GetIntBinaryString(100));
// Write full binary string for 100000.
Console.WriteLine(GetIntBinaryString(100000));
Console.ReadKey();
}
static string GetIntBinaryString(int n)
{
char[] b = new char[32];
int pos = 31;
int i = 0;
while (i < 32)
{
if ((n & (1 << i)) != 0)
{
b[pos] = '1';
}
else
{
b[pos] = '0';
}
pos--;
i++;
}
return new string(b);
}
}
/*
00000000000000000000000001100100
00000000000000011000011010100000
*/
Loading
Posted Sep 28, 2013, 10:12 PM
VulpesPosted Sep 28, 2013, 7:04 PM
If corresponding bits of the operands are both 1, then the corresponding bit of the result is 1. Otherwise it's 0.
Posted Sep 28, 2013, 4:36 PM
In the above example single & is used what does it mean? Problem is highlighted in blue colour.
VulpesPosted Sep 28, 2013, 4:23 PM
int i = Convert.ToInt32(binaryString, 2);
where binaryString is the binary number expressed as a string.
For example "00000000000000011000011010100000"
Posted Sep 28, 2013, 3:00 PM
Is there any function in C# to convert binary into decimal numbers?
Sayed Saheb AliPosted Sep 28, 2013, 2:20 PM
The left operands value is moved left by the number of bits specified by the right operand.
if A = 0011 1100
A << 2 will give 240, which is 1111 0000
here the value of A is shifted to two position in left side.
Similarly ,there is >>,known as Bitwise Right shift operator
The left operands value is moved right by the number of bits specified by the right operand.
if A=0011 1100
A >> 2 will give 15, which is 0000 1111
Please refer:
http://msdn.microsoft.com/en-us/library/a1sway8w.aspx
http://msdn.microsoft.com/en-us/library/xt18et0d.aspx
VulpesPosted Sep 28, 2013, 11:29 AM
a << b
shifts the bits in 'a' by 'b' positions to the left.
This is equivalent to multiplying 'a' by 2 to the power 'b'.
There's also a right shift operator:
a >> b
which shifts the bits in 'a' by 'b' positions to the right.
This is equivalent to dividing 'a' by 2 to the power 'b'.
Check out these links for more info on these operators:
http://msdn.microsoft.com/en-us/library/a1sway8w.aspx
http://msdn.microsoft.com/en-us/library/xt18et0d.aspx