位集替换 [英] Bitset Replacement

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

问题描述

我在DSP上使用的C ++编译器没有提供bitset

类。任何人都可以建议替换它吗?我写了很多

代码,它们使用了bitset类(在我知道编译器之前...

的不足之处),所以它需要有大约

相同的界面。


提前致谢,

比尔

I''m using a C++ compiler on a DSP that doesn''t provide the bitset
class. Can anyone suggest a replacement for it? I''ve written a lot of
code that uses the bitset class (before I knew about the...
inadequacies of the compiler), so it needs to have approximately the
same interface.

Thanks in advance,
Bill

推荐答案

2006年6月12日07:51:52 -0700,我挥挥手,这条消息

神奇地从 wo ****** @ gmail.com
On 12 Jun 2006 07:51:52 -0700, I waved a wand and this message
magically appeared from wo******@gmail.com:
我正在使用C ++编译器一个没有提供bitset
类的DSP。任何人都可以建议替换它吗?我写了很多使用bitset类的代码(在我知道编译器的不足之前),所以它需要大约有相同的接口。
I''m using a C++ compiler on a DSP that doesn''t provide the bitset
class. Can anyone suggest a replacement for it? I''ve written a lot
of code that uses the bitset class (before I knew about the...
inadequacies of the compiler), so it needs to have approximately the
same interface.




你很幸运,这里有你可以使用的东西。我特此将此

代码放入公共领域。这个帖子。


#ifndef __BINARY__

#define __BINARY __


#include< iostream>

#include< string>

#include< limits>

#include< assert.h>


class binary

{

public:

模板< typename T>

二进制(const T& n)

{

const unsigned int bits =

std :: numeric_limits< T> :: digits; for(unsigned int i = 0; i< bits; i ++)

digits.insert(digits.begin(),(n&(1<< i))?

''1'':''0'');


断言(digits.size()== bits);

} $ / $

const bool test(const unsigned int n)const

{

assert(n< digits.size() + 1);

返回(数字[n - 1] ==''1'')? true:false;

}


void set(const unsigned int n)

{

断言(n< digits.size()+ 1);

digits [n - 1] =''1'';

}


朋友std :: ostream& operator<<(std :: ostream& stream,const

binary& bin){

return stream<< bin.digits;

}


private:

std :: string digits;

} ;


#endif // __BINARY__

-
http://www.munted.org.uk

小睡一下,它可以挽救生命。



You''re in luck, here''s something you might can use. I hereby place this
code into the public domain with this post.

#ifndef __BINARY__
#define __BINARY__

#include <iostream>
#include <string>
#include <limits>
#include <assert.h>

class binary
{
public:
template <typename T>
binary(const T& n)
{
const unsigned int bits =
std::numeric_limits<T>::digits; for (unsigned int i = 0; i < bits; i++)
digits.insert(digits.begin(), (n & (1 << i)) ?
''1'' : ''0'');

assert(digits.size() == bits);
}

const bool test(const unsigned int n) const
{
assert(n < digits.size() + 1);
return (digits[n - 1] == ''1'') ? true : false;
}

void set(const unsigned int n)
{
assert(n < digits.size() + 1);
digits[n - 1] = ''1'';
}

friend std::ostream& operator<<(std::ostream& stream, const
binary& bin) {
return stream << bin.digits;
}

private:
std::string digits;
};

#endif // __BINARY__
--
http://www.munted.org.uk

Take a nap, it saves lives.


wo******@gmail.com 写道:
我在没有提供bitset
类的DSP上使用C ++编译器。任何人都可以建议替换它吗?我写了很多使用bitset类的代码(在我知道编译器的不足之前),所以它需要大约有相同的接口。
I''m using a C++ compiler on a DSP that doesn''t provide the bitset
class. Can anyone suggest a replacement for it? I''ve written a lot
of code that uses the bitset class (before I knew about the...
inadequacies of the compiler), so it needs to have approximately the
same interface.




呃......获得一个免费的库实现,比如STLport或GNU,以及

重复使用他们的位置。 AFAICT,大部分(如果不是全部)都在

标题中。如果您的编译器没有它,也许它仍然可以编译

其他人已实现...


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问



Uh... Get a free library implementation, like STLport or GNU, and
"re-use" their bitset. AFAICT, most if not all of it is in the
header. If your compiler doesn''t have it, maybe it still can compile
the one others have implemented...

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


> >我在DSP上使用的是C ++编译器,它没有提供bitset
> > I''m using a C++ compiler on a DSP that doesn''t provide the bitset
类。任何人都可以建议替换它吗?我写了很多使用bitset类的代码(在我知道编译器的不足之前),所以它需要大约有相同的接口。
class. Can anyone suggest a replacement for it? I''ve written a lot
of code that uses the bitset class (before I knew about the...
inadequacies of the compiler), so it needs to have approximately the
same interface.


呃......获得一个免费的库实现,比如STLport或GNU,以及
re-use他们的位置。 AFAICT,大部分(如果不是全部)都在
标题中。如果您的编译器没有它,也许它仍然可以编译
其他人已经实现...

Uh... Get a free library implementation, like STLport or GNU, and
"re-use" their bitset. AFAICT, most if not all of it is in the
header. If your compiler doesn''t have it, maybe it still can compile
the one others have implemented...




是的,这将是一个理想的解。我已经尝试过,使用Visual C ++和g ++中的

bitset标头。但是它们都依赖于供应商库实现中的其他定义

。而且我不认为
认为开始将越来越多的图书馆复制到我的项目中是个好主意。


但是,我还没有签出STLport。我会好好看看

吧。谢谢你的建议。


- 比尔



Yes, that would be an ideal solution. And I have tried that, with the
bitset header from both Visual C++ and g++. But both of them depend on
other definitions in the vendor''s library implementation. And I don''t
think it would be a good idea to start copying more and more pieces of
the library in to my project.

However, I have not checked out STLport. I''ll look in to that right
now. Thanks for the suggestion.

--Bill


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

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