学用ASP.NetのSystemCollections.Specialized.BitVector 32構造
8401 ワード
BitVector 32の構成は32ビットサイズの格納スペース(Intel 32と同様)のみを提供する、これによりブール値や小整数(例えば7以内や15以内の小整数など)に素早くアクセスできる.
主要メンバー:
構築方法:
配列型アクセス:
各ビットに個別にアクセスするには、次の手順に従います.
BitVector32.CreateMask():
BitVector32.CreateSection():
複数のセッションを作成するには、次の手順に従います.
BitVector32.CreateSection()が返すBitVector 32.Sectionも構造体です.
主要メンバー:
/* */
Data; // 32 , ; BitVector32
/* */
BitVector32.CreateMask(); // Mask
BitVector32.CreateSection(); // BitVector32.Section
BitVector32.ToString(); // BitVector32
/* */
ToString(); //
/* BitVector32.Section */
Mask; //
Offset; //
構築方法:
protected void Button1_Click(object sender, EventArgs e)
{
BitVector32 bv1 = new BitVector32(); // new BitVector32(0);
BitVector32 bv2 = new BitVector32(0); // 32 0
BitVector32 bv3 = new BitVector32(0x0000FF0F); // int " "
BitVector32 bv4 = new BitVector32(bv3); // BitVector32
BitVector32 bv5 = new BitVector32(-1); //
string s1 = bv1.ToString(); //BitVector32{00000000000000000000000000000000}
string s2 = bv2.ToString(); //BitVector32{00000000000000000000000000000000}
string s3 = bv3.ToString(); //BitVector32{00000000000000001111111100001111}
string s4 = bv4.ToString(); //BitVector32{00000000000000001111111100001111}
string s5 = bv5.ToString(); //BitVector32{11111111111111111111111111111111}
TextBox1.Text = s1 + "
" + s2 + "
" + s3 + "
" + s4 + "
" + s5;
}
配列型アクセス:
// BitVector32 , UInt32.MaxValue .
protected void Button1_Click(object sender, EventArgs e)
{
BitVector32 bv = new BitVector32(0);
bv[1] = true;
string s1 = bv.ToString(); //BitVector32{00000000000000000000000000000001}
bv[-1] = false; bv[2] = true; //
string s2 = bv.ToString(); //BitVector32{00000000000000000000000000000010}
bv[-1] = false; bv[3] = true; //BitVector32{00000000000000000000000000000011}
string s3 = bv.ToString();
bv[-1] = false; bv[4] = true; //BitVector32{00000000000000000000000000000100}
string s4 = bv.ToString();
bv[-1] = false; bv[5] = true; //BitVector32{00000000000000000000000000000101}
string s5 = bv.ToString();
bv[-1] = false; bv[6] = true; //BitVector32{00000000000000000000000000000110}
string s6 = bv.ToString();
bv[-1] = false; bv[7] = true; //BitVector32{00000000000000000000000000000111}
string s7 = bv.ToString();
bv[-1] = false; bv[Int32.MaxValue] = true; //BitVector32{01111111111111111111111111111111}
string s8 = bv.ToString();
TextBox1.Text = s1 + "
" + s2 + "
" + s3 + "
" + s4 + "
" + s5 + "
" + s6 + "
" + s7 + "
" + s8;
}
各ビットに個別にアクセスするには、次の手順に従います.
// (Mask)
protected void Button1_Click(object sender, EventArgs e)
{
BitVector32 bv = new BitVector32(0);
int n1 = (int)Math.Pow(2, 0);
int n2 = (int)Math.Pow(2, 1);
int n3 = (int)Math.Pow(2, 2);
int n4 = (int)Math.Pow(2, 3);
int n5 = (int)Math.Pow(2, 4);
int n32 = (int)Math.Pow(2, 31);
bv[n3] = true;
string s1 = bv.ToString(); //BitVector32{00000000000000000000000000000100}
bv[n1] = true;
bv[n2] = true;
bv[n3] = true;
bv[n4] = true;
bv[n5] = true;
bv[n32] = true;
string s2 = bv.ToString(); //BitVector32{10000000000000000000000000011111}
bv[-1] = true; //
bv[n1] = false;
bv[n2] = false;
bv[n3] = false;
bv[n4] = false;
bv[n5] = false;
bv[n32] = false;
string s3 = bv.ToString(); //BitVector32{01111111111111111111111111100000}
TextBox1.Text = s1 + "
" + s2 + "
" + s3;
}
BitVector32.CreateMask():
// BitVector32
protected void Button1_Click(object sender, EventArgs e)
{
BitVector32 bv = new BitVector32(0);
int mk1 = BitVector32.CreateMask(); // Mask, BitVector32.CreateMask(0);
int mk2 = BitVector32.CreateMask(mk1); // mk1 mk2
int mk3 = BitVector32.CreateMask(mk2); // mk2 mk3
int mk4 = BitVector32.CreateMask(mk3); //
int mk5 = BitVector32.CreateMask(mk4); //
//mk1 .. mk5 : 1、2、4、8、16
bv[mk3] = true;
string s1 = bv.ToString(); //BitVector32{00000000000000000000000000000100}
bv[mk1] = true;
bv[mk2] = true;
bv[mk3] = true;
bv[mk4] = true;
bv[mk5] = true;
string s2 = bv.ToString(); //BitVector32{00000000000000000000000000011111}
bv[-1] = true; //
bv[mk1 | mk2 | mk3 | mk4 | mk5] = false; // "|" "+" Mask
string s3 = bv.ToString(); //BitVector32{11111111111111111111111111100000}
TextBox1.Text = s1 + "
" + s2 + "
" + s3;
}
BitVector32.CreateSection():
// 0..7 , 3 ;
//BitVector32.CreateSection(n) BitVector32 0..n Section( )
protected void Button1_Click(object sender, EventArgs e)
{
BitVector32 bv = new BitVector32(0);
BitVector32.Section sec = BitVector32.CreateSection(7);
string s0, s1, s2, s3, s4, s5, s6, s7;
bv[sec] = 0; s0 = bv.ToString(); //BitVector32{00000000000000000000000000000000}
bv[sec] = 1; s1 = bv.ToString(); //BitVector32{00000000000000000000000000000001}
bv[sec] = 2; s2 = bv.ToString(); //BitVector32{00000000000000000000000000000010}
bv[sec] = 3; s3 = bv.ToString(); //BitVector32{00000000000000000000000000000011}
bv[sec] = 4; s4 = bv.ToString(); //BitVector32{00000000000000000000000000000100}
bv[sec] = 5; s5 = bv.ToString(); //BitVector32{00000000000000000000000000000101}
bv[sec] = 6; s6 = bv.ToString(); //BitVector32{00000000000000000000000000000110}
bv[sec] = 7; s7 = bv.ToString(); //BitVector32{00000000000000000000000000000111}
TextBox1.Text = s0 + "
" + s1 + "
" + s2 + "
" + s3 + "
" + s4 + "
" + s5 + "
" + s6 + "
" + s7;
}
複数のセッションを作成するには、次の手順に従います.
// Section , BitVector32.CreateMask() , , .
protected void Button1_Click(object sender, EventArgs e)
{
BitVector32 bv = new BitVector32(0);
BitVector32.Section secX = BitVector32.CreateSection(15); // Section, 0..15
BitVector32.Section secY = BitVector32.CreateSection(7, secX); //secX Section, 0..7
BitVector32.Section secZ = BitVector32.CreateSection(15, secY); //secY Section, 0..15
// : 000000000000000000000ZZZZYYYXXXX
bv[secX] = 15;
bv[secY] = 0;
bv[secZ] = 15;
string s1 = bv.ToString(); //BitVector32{00000000000000000000011110001111}
bv[secX] = 1;
bv[secY] = 1;
bv[secZ] = 1;
string s2 = bv.ToString(); //BitVector32{00000000000000000000000010010001}
TextBox1.Text = s1 + "
" + s2;
}
BitVector32.CreateSection()が返すBitVector 32.Sectionも構造体です.
protected void Button1_Click(object sender, EventArgs e)
{
BitVector32 bv = new BitVector32(0);
BitVector32.Section secX = BitVector32.CreateSection(15);
BitVector32.Section secY = BitVector32.CreateSection(7, secX);
BitVector32.Section secZ = BitVector32.CreateSection(15, secY);
TextBox1.Text = string.Format("{0}, {1}, {2}
", secX.Mask, secY.Mask, secZ.Mask); //15, 7, 15
TextBox1.Text += string.Format("{0}, {1}, {2}
", secX.Offset, secY.Offset, secZ.Offset); //0, 4, 7
}