标签: bitset

无法在VC++中编译头文件

我刚刚重新组织了一个项目的代码,现在我遇到了无法解决的错误.此标头包含在尝试编译的.cpp文件中.

#include "WinMain.h"
#include "numDefs.h"
#include <bitset>

class Entity
{
public:
    Entity();
    virtual ~Entity();

    virtual bitset<MAX_SPRITE_PIXELS> getBitMask();
    virtual void getMapSection(float x, float y, int w, int h, bitset<MAX_SPRITE_PIXELS>* section);
};
Run Code Online (Sandbox Code Playgroud)

我为Entity :: getBitMask()的声明得到了这些编译器错误:

错误C2143:语法错误:缺少';' 在'<'之前

错误C2433:'Entity :: bitset':数据声明中不允许'virtual'

错误C4430:缺少类型说明符 - 假定为int.注意:C++不支持default-int

错误C2238:';'之前的意外标记

下一行也有更多类似的错误.似乎bitset没有被包括但显然是?我无法弄清楚出了什么问题.WinMain.h包含windows.h,numDefs.h不包含任何内容.

使用MS Visual C++ 2008.

c++ bitset visual-c++

1
推荐指数
2
解决办法
392
查看次数

Bitsets真的会沸腾吗?

在C++中,bitsets实际上是一组bool吗?这不会破坏使用BitSet的目的,因为bools是32位(我认为......)?

c++ bitset

1
推荐指数
2
解决办法
274
查看次数

正则表达式"\\ d +"在字符串中找到两次整数:"{10}".匹配器匹配10和0

我使用正则表达式将BitSet normal toString转换为二进制字符串.例如,如果myBitSet.toString()返回{10},它会设置第10位和第0位,但应该只设置第10位.

    ...
    Matcher m = Pattern.compile("(?=(" + "\\d+" + "))").matcher(temp);
    while(m.find()) {
        String test2 = m.group(1);
        answer.setCharAt((2*OpSize -1 - Integer.valueOf(m.group(1))), '1');

    }
    .....
Run Code Online (Sandbox Code Playgroud)

regex matcher bitset

1
推荐指数
1
解决办法
91
查看次数

位向量和位集

stl的bit-vector和bitset容器有什么区别?请解释.我理解bitset是bitvector概念的实现我是对还是错?实现位向量的其他方法有哪些?

c++ stl bitvector bitset

1
推荐指数
1
解决办法
5898
查看次数

如何设置特定位?

假设我有一个uint16_t变量,我必须设置特定的位.

例:

uint16_t field = 0;

这意味着这些位都是零: 0000 0000 0000 0000

现在我得到了一些我需要在特定位置设置的值.

val1=1; val2=2, val3=0, val4=4, val5=0;

如何设置位的结构如下

0|000|  0000| 0000 000|0
Run Code Online (Sandbox Code Playgroud)

val1应该设置在左边的第一位.所以它只有一个或零.

val2应该设置在接下来的三位.val3在接下来的四位上.val4在接下来的七位和val5一位最后一位.

结果是这样的: 1010 0000 0000 1000

我只发现了一个特定的位而不是"组".(移位或bitset)

有谁知道如何解决这个问题?

c++ shift bit bitset

1
推荐指数
1
解决办法
5592
查看次数

<<运算符重载模板类对象

我写过类似C++的STL bitset:

template<size_t N>
class bitset {
public:
 ...........
 friend std::ostream& operator << (std::ostream &, bitset<N> const&);
private:
 ..........
};
// end of class

template<size_t N>
std::ostream& operator << (std::ostream &os, bitset<N> const& rhs) {
    ............
    .........
    return os;
}
Run Code Online (Sandbox Code Playgroud)

我试图像这样使用它:

bitset<5> foo; // success
std::cout << foo << std::endl; // fail
Run Code Online (Sandbox Code Playgroud)

错误信息是 -

undefined reference to `operator<<(std::ostream&, bitSet<5u> const&)
Run Code Online (Sandbox Code Playgroud)

实际上有什么问题?

c++ templates stl bitset c++11

1
推荐指数
1
解决办法
215
查看次数

为 Bitset 赋值

我很想知道为什么下面的代码有效!根据 bitset 模板类,您可以通过构造函数为 bitset(int 或二进制表示为字符串)赋值,但之后不能。但是在这里你可以看到显式分配一个整数工作正常。

#include <iostream>
#include <bitset>
#include <string>
using namespace std;

int main()
{
    bitset<8> b(string("101"));
    cout << b.to_ullong()<<"\n";
    b= 145;
    cout << b<<"\n";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这个问题也可能是相关的。 初始化后如何从字符串中分配位集值

c++ bitset c++11

1
推荐指数
1
解决办法
4021
查看次数

Java Bitset初始化

我正在为我的程序使用BitSet类.我需要一个内联声明,如:

BitSet bits1 = new BitSet(); //standard declaration
bits1.set(0,2);
bits1.set(4,6);
System.out.println(bits1); //110011

BitSet bits2 = BitSet.valueOf(new long[] {1,1,0,0,1,1}); //inline
System.out.println(bits2);
Run Code Online (Sandbox Code Playgroud)

有了这个代码,我试图复制相同的位集合是在BITS1,在BITS2.问题如下:打印和值不同.我设置的BitSet是110011.第一个打印出{0,1,4,5}并且它是正确的,因为这是用索引打印BitSet的"好方法",第二个打印出{0,64, 256,320}.你可以看到第二个是错的.我很确定内联初始化是错误的,但我无法弄清楚如何解决这个问题.

java initialization bitset

1
推荐指数
1
解决办法
1181
查看次数

Java BitSet size() 行为

由于存在库,我计划使用 BitSet 来操作 byte[] 中的位。

但是,似乎在从 byte[] 创建 BitSet 之后,BitSet 的最小大小为 64,否则最终为零。是否要求必须有 8 个字节?此外,等于零的 byte[] 将始终以零大小显示。我认为它仍然会输出字节数组的大小?

IE。

BitSet bs1 = BitSet.valueOf(new byte[] {0, 0, 0, 0, 0, 0, 1});  // bs1.size() == 64
BitSet bs2 = BitSet.valueOf(new byte[] {0, 0, 0, 0, 0, 0, 0, 1}); // bs2.size() == 64
BitSet bs3 = BitSet.valueOf(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 1});  // bs3.size() == 128
BitSet bs4 = BitSet.valueOf(new byte[] {0, 0, 0, 0, 0, 0, 0, …
Run Code Online (Sandbox Code Playgroud)

java arrays bitset

1
推荐指数
1
解决办法
170
查看次数

Java BitSet.size() 没有返回我在构造函数中给出的大小

我有以下代码:

 private BitSet arrayListToBitSet(ArrayList<Boolean> code) {
                // The problem is here, the bitset automatically is created using 64 bits even tho we are clearly 
                    // giving it a max size in constructor, and in the test we are running,
                    // we are only using 9 bits, leading to the rest of the bits being automatically 0, so we need to
                    // search for a way that the size of the bitset is exactly the size of the array list "code" …
Run Code Online (Sandbox Code Playgroud)

java bit bitset

1
推荐指数
1
解决办法
108
查看次数

标签 统计

bitset ×10

c++ ×6

java ×3

bit ×2

c++11 ×2

stl ×2

arrays ×1

bitvector ×1

initialization ×1

matcher ×1

regex ×1

shift ×1

templates ×1

visual-c++ ×1