从位创建一个int [英] creating an int from bits

查看:111
本文介绍了从位创建一个int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我将会有一系列位标志,我可以存储在

数组中,或者作为字符串存储(" 10011001),或任何其他方式。


我希望能够将这一系列的位转换为int。我知道C ++

必须有一些类或内置功能,但我的网页

搜索到目前为止还没有找到它。有人能让我知道我应该使用什么吗?


我对如何存储比特很灵活,所以我正在为

也是如此。理想情况下,我想要任何比特的存储和

比特转换机制最快。


感谢任何想法,

cpp

Hi,

I am going to have a series of bit flags which I could store in an
array, or as a string ("10011001"), or any other way.

I want to be able to turn this series of bits into an int. I know C++
must have some class or built-in functionality for this, but my web
searching thus far hasn''t found it. Can someone let me know what I
should use?

I am flexible on how to store the bits, so I''m taking suggestions for
that too. Ideally, I want whatever combination of bit-storage and
bit-to-int conversion mechanism is fastest.

Thanks for any ideas,
cpp

推荐答案

cppaddict写道:
cppaddict wrote:

我将有一系列位标志,我可以存储在一个
数组中,或者作为一个字符串(10011001)或任何其他方式。

我想要能够将这一系列的位转换为int。我知道C ++
必须有一些类或内置功能,但到目前为止我的网站搜索还没有找到它。有人能让我知道我应该使用什么吗?

我对如何存储这些内容很灵活,所以我也在为
提供建议。理想情况下,我希望位存储和位转换机制的任何组合都是最快的。
Hi,

I am going to have a series of bit flags which I could store in an
array, or as a string ("10011001"), or any other way.

I want to be able to turn this series of bits into an int. I know C++
must have some class or built-in functionality for this, but my web
searching thus far hasn''t found it. Can someone let me know what I
should use?

I am flexible on how to store the bits, so I''m taking suggestions for
that too. Ideally, I want whatever combination of bit-storage and
bit-to-int conversion mechanism is fastest.




多少位?你想如何处理比可以装入int更多的b $ b位的情况?


Jacques。



How many bits? How do you want to handle the case where there are more
bits than can fit into an int?

Jacques.




" cppaddict" <他*** @ hello.com>在留言中写道

新闻:2v ******************************** @ 4ax.com ...

"cppaddict" <he***@hello.com> wrote in message
news:2v********************************@4ax.com...


我将有一系列位标志,我可以存储在一个
数组中,或者作为一个字符串( 10011001),或任何其他方式。

我希望能够将这一系列的位转换为int。我知道C ++
必须有一些类或内置功能,但到目前为止我的网站搜索还没有找到它。有人能让我知道我应该使用什么吗?


bitset如果你有一个固定的位数。矢量< BOOL> (我猜)如果它是

变量。

我对如何存储这些位很灵活,所以我也在接受
的建议。理想情况下,我想要任何位存储和/或位转换机制的组合是最快的。
Hi,

I am going to have a series of bit flags which I could store in an
array, or as a string ("10011001"), or any other way.

I want to be able to turn this series of bits into an int. I know C++
must have some class or built-in functionality for this, but my web
searching thus far hasn''t found it. Can someone let me know what I
should use?
bitset if you have a fixed number of bits. vector<bool> (I guess) if it is
variable.

I am flexible on how to store the bits, so I''m taking suggestions for
that too. Ideally, I want whatever combination of bit-storage and
bit-to-int conversion mechanism is fastest.




如果我需要速度我想我会存储直接在无符号的位

int。


john



If I needed speed I think I would store the bits directly in an unsigned
int.

john


多少位?你想如何处理比int更多的
位的情况?

Jacques。
How many bits? How do you want to handle the case where there are more
bits than can fit into an int?

Jacques.




我永远不会超过18位。



I will never have more than 18 bits.


这篇关于从位创建一个int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆