Firstly, to convert a number to a binary string you simply do this:
CSharp Code:
myString = Convert.ToString(myNumber, 2);
You can pad that with zeroes if you like, taking note that the long type is 64 bits wide, not 32:
CSharp Code:
myString = Convert.ToString(myNumber, 2).PadLeft(64, '0');
Finally, it would be better to create your own structure for this:
Code:
public struct UserPermissions
{
long value;
public bool this[int index]
{
get
{
if (index < 0 || index > 63)
{
throw new ArgumentOutOfRangeException("index",
index,
"Index values must be within the range 0 to 63 inclusive.");
}
return Convert.ToBoolean(this.value & Convert.ToInt64(Math.Pow(2, index)));
}
set
{
if (index < 0 || index > 63)
{
throw new ArgumentOutOfRangeException("index",
index,
"Index values must be within the range 0 to 63 inclusive.");
}
if (value)
{
this.value |= Convert.ToInt64(Math.Pow(2, index));
}
else
{
this.value &= (long.MaxValue ^ Convert.ToInt64(Math.Pow(2, index)));
}
}
}
public UserPermissions(long value)
{
this.value = value;
}
public long ToInt64()
{
return this.value;
}
}