o,1的感悟

现在每天用着高级语言编写着业务软件,渐渐感觉远离0,1了。不懂0,1一样写的很好的程序,但时常感觉心里很空,以前都是冲低级语言向高级语言。最近有种由高向低的进发,今天写个小程序纪念下:

这个程序实现了对一个整数某位的判断,这里用了C#的索引。

using System;
using System.Collections.Generic;
using System.Text;

namespace bits
{
    class bit 
    {
        private int bits;
        public bit(int bits)
        {
            this.bits = bits;
        }
        //index
        public bool this[int index]
        {
            get
            {
                return (bits & (1 << index)) != 0;
            }
            set
            {
                if (value)
                    bits |= (1 << index );
                else
                    bits &= ~(1 << index);
            }
        }
    }
}

posted @ 2008-04-08 20:48  HonestMan  阅读(208)  评论(0编辑  收藏  举报