Numbering conventions of strings and bitsets
2014-01-24 11:52
344 查看
转载自:C++ Primer, Fifth Edition
The indexing conventions of strings and bitsets are inversely related:The character in the string with the highest subscript (the rightmostcharacter) is used to initialize the low-order bit
in the bitset (the bit withsubscript 0). When you initialize a bitset from a string, it is essential to remember this difference.
For example:
string str("1111111000000011001101");
bitset<32> bitvec5(str, 5, 4); // four bits starting at str[5], 1100
bitset<32> bitvec6(str, str.size()-4); // use last four characters
We can view these initializations as
Here bitvec5 is initialized by the substring in str starting at str[5] and continuing for four positions. As usual, the right-most character of the substring represents the lowest-order bit. Thus, bitvec5 is initialized with bit
positions 3 through 0 set to 1100 and the remaining bits set to 0. The initializer for bitvec6 passes a string and a starting point, so bitvec6 is initialized from the characters in str starting four from the end of str. The remainder of the bits in bitvec6
are initialized to zero.
The indexing conventions of strings and bitsets are inversely related:The character in the string with the highest subscript (the rightmostcharacter) is used to initialize the low-order bit
in the bitset (the bit withsubscript 0). When you initialize a bitset from a string, it is essential to remember this difference.
For example:
string str("1111111000000011001101");
bitset<32> bitvec5(str, 5, 4); // four bits starting at str[5], 1100
bitset<32> bitvec6(str, str.size()-4); // use last four characters
We can view these initializations as
Here bitvec5 is initialized by the substring in str starting at str[5] and continuing for four positions. As usual, the right-most character of the substring represents the lowest-order bit. Thus, bitvec5 is initialized with bit
positions 3 through 0 set to 1100 and the remaining bits set to 0. The initializer for bitvec6 passes a string and a starting point, so bitvec6 is initialized from the characters in str starting four from the end of str. The remainder of the bits in bitvec6
are initialized to zero.
相关文章推荐
- CloudStack 实现VM高可用特性
- linux使用scp命令备份文件 scp拷贝文件
- sql 查询
- 声音和电磁波
- 关于未来超高效存储设备的设想
- GNS3路由器与模拟三层交换的交换模块相连时不能全双工
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- 如何让CloudStack使用KVM创建Windows实例成功识别并挂载数据盘
- 石基信息:战略性收购思迅软件,线下支付平台布局完善
- C#調用User32api
- timer-----内核定时器
- 特写:逐浪CMS失败的五个支点兼谈中国软件业的发展之现状
- windows下体验Redis
- Effective JavaScript 读书笔记 1 严格模式
- 如何打造一份超级简历
- 使用Google code + SVN进行多人开发
- header导出Excel你做过吗?
- Java编程中实现Cloneable接口,让类的对象可以复制
- IT运维外包甩不掉的包袱
- Bitmap回收异常:Canvas: trying to use a recycled bitmap android.graphics.Bitmap解决