110,502
社区成员
发帖
与我相关
我的任务
分享
public struct unBitConvert
{
int innerValue;
public byte ucValue
{
get { return (byte)(innerValue & 0xff); }
set { innerValue = value; }
}
public bool Bit0
{
get
{
return (innerValue & 1) != 0;
}
set
{
if (value)
{
innerValue |= 1;
}
else
{
innerValue &= ~1;
}
}
}
public bool Bit1
{
get
{
return (innerValue & 2) != 0;
}
set
{
if (value)
{
innerValue |= 2;
}
else
{
innerValue &= ~2;
}
}
}
public bool Bit2
{
get
{
return (innerValue & 4) != 0;
}
set
{
if (value)
{
innerValue |= 4;
}
else
{
innerValue &= ~4;
}
}
}
public bool Bit3
{
get
{
return (innerValue & 8) != 0;
}
set
{
if (value)
{
innerValue |= 8;
}
else
{
innerValue &= ~8;
}
}
}
public bool Bit4
{
get
{
return (innerValue & 16) != 0;
}
set
{
if (value)
{
innerValue |= 16;
}
else
{
innerValue &= ~16;
}
}
}
public bool Bit5
{
get
{
return (innerValue & 32) != 0;
}
set
{
if (value)
{
innerValue |= 32;
}
else
{
innerValue &= ~32;
}
}
}
public bool Bit6
{
get
{
return (innerValue & 64) != 0;
}
set
{
if (value)
{
innerValue |= 64;
}
else
{
innerValue &= ~64;
}
}
}
public bool Bit7
{
get
{
return (innerValue & 128) != 0;
}
set
{
if (value)
{
innerValue |= 128;
}
else
{
innerValue &= ~128;
}
}
}
}
static byte modMult02(byte x)
{
byte[] t = new byte[] { x };
BitArray input = new BitArray(t);
BitArray output = new BitArray(8);
output[0] = input[7];
output[7] = input[6];
output[6] = input[5];
output[5] = input[4];
output[2] = input[1];
output[1] = input[0] ^ input[7];
output[3] = input[2] ^ input[7];
output[4] = input[3] ^ input[7];
output.CopyTo(t, 0);
return t[0];
}