GetBit SetBit

   /// <summary>
         /// 设置某一位的值
        /// </summary>
         /// <param name="data"></param>
         /// <param name="index">要设置的位, 值从低到高为 1-8</param>
         /// <param name="flag">要设置的值 true / false</param>
         /// <returns></returns>
         byte set_bit(byte data, int index, bool flag)
         {
             if (index > 8 || index < 1)
                 throw new ArgumentOutOfRangeException();
             int v = index < 2 ? index : (2 << (index - 2));
             return flag ? (byte)(data | v) : (byte)(data & ~v);
         }
    /// <summary>
        /// 获取数据中某一位的值
        /// </summary>
        /// <param name="input">传入的数据类型,可换成其它数据类型,比如Int</param>
        /// <param name="index">要获取的第几位的序号,从0开始</param>
        /// <returns>返回值为-1表示获取值失败</returns>
        private int GetbitValue(byte input,int index)
        {
            if (index > sizeof(byte))
            {
                return -1;
            }
            //左移到最高位
            int value = input << (sizeof(byte) - 1 - index);
            //右移到最低位
            value = value >> (sizeof(byte) - 1);
            return value;
        }
时间: 2024-08-06 11:32:08

GetBit SetBit的相关文章

&lt;Redis&gt;&lt;Pipelining&gt;

Overview About Redis pipelining About Redis memory optimization About Redis expire About Redis transactions Pipelining Request/Response protocols and RTT Redis is a TCP server using the client-server model and what is called a Request/Response protoc

redis中文文档

phpredis是php的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务关系 很有用;以下是redis官方提供的命令使用技巧: 下载地址如下: https://github.com/owlient/phpredis(支持redis 2.0.4) Redis::__construct构造函数$redis = new Redis(); connect, open 链接redis服务参数host: string,服务地址port: int,端口号timeout: float,链接时长 (

redis 操作大全 PHP-redis中文文档

转自  : http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html phpredis是php的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务关系 很有用;以下是redis官方提供的命令使用技巧: 下载地址如下: https://github.com/owlient/phpredis(支持redis 2.0.4) Redis::__construct构造函数$redis = new Redis(); connect,

PHP-redis api 中文说明(转)

来源 : http://hi.baidu.com/gaolamp/item/1686aac07334bd0f0ad93a9f PHP-redis api 中文说明 phpredis 是 php 的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务 关系,很有用,以下是 redis 官方提供的命令使用技巧: 下载地址如下: https://github.com/owlient/phpredis(支持 redis 2.0.4) Redis::__construct 构造函数 $redis

PHP-redis中文文档

phpredis是php的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务关系 很有用;以下是redis官方提供的命令使用技巧: 下载地址如下: https://github.com/owlient/phpredis(支持redis 2.0.4) Redis::__construct构造函数$redis = new Redis(); connect, open 链接redis服务参数host: string,服务地址port: int,端口号timeout: float,链接时长 (

二、Reids基础命令--字符串

11.一个字符串类型的KEY同意存储的数据的最大容量是 512MB 12.INCR 使key加1,key不存在时默认是0 . 返回递增后的值. 127.0.0.1:6379> incr num (integer) 1 127.0.0.1:6379> get num "1" 13.INCRBY 能够指定添加的步长 127.0.0.1:6379> incrby index 3 (integer) 3 14.decr 使KEY减1 127.0.0.1:6379> de

redis的使用

phpredis是php的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务关系 很有用;以下是redis官方提供的命令使用技巧: 下载地址如下: https://github.com/owlient/phpredis(支持redis 2.0.4) Redis::__construct构造函数$redis = new Redis(); connect, open 链接redis服务参数host: string,服务地址port: int,端口号timeout: float,链接时长 (

Redis 5种数据结构使用及注意事项

1优缺点 非常非常的快,有测评说比Memcached还快(当大家都是单CPU的时候),而且是无短板的快,读写都一般的快,所有API都差不多快,也没有MySQL Cluster.MongoDB那样更新同一条记录如Counter时慢下去的毛病. 丰富的数据结构,超越了一般的Key-Value数据库而被认为是一个数据结构服务器.组合各种结构,限制Redis用途的是你自己的想象力,作者自己捉刀写的用途入门. 因为是个人作品,Redis目前只有2.3万行代码,Keep it simple的死硬做法,使得普

PHP redis使用命令

很有用;以下是redis官方提供的命令使用技巧: 下载地址如下: https://github.com/owlient/phpredis(支持redis 2.0.4) Redis::__construct构造函数$redis = new Redis(); connect, open 链接redis服务参数host: string,服务地址port: int,端口号timeout: float,链接时长 (可选, 默认为 0 ,不限链接时间)注: 在redis.conf中也有时间,默认为300 p