笔记9

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.IO;
using System.Windows.Forms;

namespace 各种测试
{
    
class Program
    {
        
static void Main(string[] args)
        {
            BitVector32 bv321 
= new BitVector32(-1);
            Console.WriteLine(bv321.Data.ToString());
            Console.WriteLine(bv321);
            
//打印
            
//-1
            
//BitVector32{11111111111111111111111111111111}

            BitVector32 bv322 
= new BitVector32(1);
            Console.WriteLine(bv322.Data.ToString());
            Console.WriteLine(bv322);
            
//打印
            
//1
            
//BitVector32{00000000000000000000000000000001}

            MemoryStream ms 
= new MemoryStream();
            StreamWriter sw 
= new StreamWriter(ms);
            sw.WriteLine(
"hello");
            sw.WriteLine(
"goodbye");
            sw.Flush();
            FileStream fs 
= File.Create(@"c:\litao.txt");
            ms.WriteTo(fs);
            fs.Close();
            sw.Close();
            ms.Close();

            FileStream fs1 
= File.Create(@"c:\litao.txt");//Create改写(条件是文件已经存在)或者创建文件,目的是为了写。
            
//CreateText打开和创建文件,目的也是为了写。
            
//FileStream fs1 = File.CreateText(@"c:\litao.txt");//作用同上,但CreateTex线程更安全。
            BufferedStream bs1 = new BufferedStream(fs1);
            StreamWriter sw1 
= new StreamWriter(bs1);
            sw1.WriteLine(
"hi,litao!");
            sw1.Close();


            
//1    decimal 1
            int myBit1 = BitVector32.CreateMask();
            
//10   decimal 2
            int myBit2 = BitVector32.CreateMask(myBit1);
            
//100  decimal 4
            int myBit3 = BitVector32.CreateMask(myBit2);
            
//1000 decimal 8
            int myBit4 = BitVector32.CreateMask(myBit3);
            MessageBox.Show(String.Format(
"{0}, {1}, {2}, {3}", myBit1, myBit2, myBit3, myBit4));

            BitVector32.Section sectionA 
= BitVector32.CreateSection(3);
            BitVector32.Section sectionB 
= BitVector32.CreateSection(127, sectionA);
            BitVector32.Section sectionC 
= BitVector32.CreateSection(127, sectionB);
            BitVector32.Section sectionD 
= BitVector32.CreateSection(127, sectionC);
            BitVector32.Section sectionE 
= BitVector32.CreateSection(255, sectionD);
            
// Create the sections
            
// AA BBBBBBB CCCCCCC DDDDDDD EEEEEEEE
            BitVector32 word = new BitVector32(0x7fffffff);
            
int A = word[sectionA];
            
int B = word[sectionB];
            
int C = word[sectionC];
            
int D = word[sectionD];
            
int E = word[sectionE];
            MessageBox.Show(String.Format(
"{0}, {1}, {2}, {3}", A, B, C, D, E));


            Console.Read();
        }
    }
}
posted @ 2008-04-19 04:03  李涛  阅读(186)  评论(0)    收藏  举报