65,187
社区成员




byte testBytes[5]= {0x1,0x2,0x3,0x4,0x0};
std::bitset<40> temp2;
unsigned int n = 0;
for( unsigned int i = 0; i < 5; ++ i)
{
for( unsigned int j = 0; j < 8; ++ j)
{
temp2[n] = testBytes[i] >> j;
++ n;
}
}
[/quote]
不对啊,我提供一个数组进行测试:
byte testBytes[4]={0xDA, 0xA8, 0xB4,0x00}; //即二进制:1011 0100 1010 1000 1101 1010
std::bitset<32> temp2; //已经改成32位的了
unsigned int n = 0;
for( unsigned int i = 0; i < 32/8; ++ i)
{
for( unsigned int j = 0; j < 8; ++ j)
{
temp2[n] = testBytes[i] >> j;
++ n;
}
}
return 0;
temp2 = [32](1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0)
[/quote]
byte testBytes[5]= {0x1,0x2,0x3,0x4,0x0};
std::bitset<40> temp2;
unsigned int n = 0;
for( unsigned int i = 0; i < 5; ++ i)
{
for( unsigned int j = 0; j < 8; ++ j)
{
temp2[n] = testBytes[i] >> j;
++ n;
}
}
[/quote]
不对啊,我提供一个数组进行测试:
byte testBytes[4]={0xDA, 0xA8, 0xB4,0x00}; //即二进制:1011 0100 1010 1000 1101 1010
std::bitset<32> temp2; //已经改成32位的了
unsigned int n = 0;
for( unsigned int i = 0; i < 32/8; ++ i)
{
for( unsigned int j = 0; j < 8; ++ j)
{
temp2[n] = testBytes[i] >> j;
++ n;
}
}
return 0;
temp2 = [32](1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0)
byte testBytes[5]= {0x1,0x2,0x3,0x4,0x0};
std::bitset<40> temp2;
unsigned int n = 0;
for( unsigned int i = 0; i < 5; ++ i)
{
for( unsigned int j = 0; j < 8; ++ j)
{
temp2[n] = testBytes[i] >> j;
++ n;
}
}
byte testBytes[5]={0x1,0x2,0x3,0x4,0x0}; //vc环境下
std::string strHelp((char*)testBytes);
#if 1
int nTemp=strHelp.length(); //nTemp==4 ?
#endif
std::bitset<40> temp2(strHelp); //崩溃
你要构造一个什么样的bitset?
使用string类型构造bitset时,string中应该只有字符'0'和'1’,'0'表示该位为0,‘1'表示该位为1。你的string中的四个字符全都是非法字条。