bitset 数据是否以相反的顺序存储?
is bitset data stored in reverse order?
我正在试用 std::bitset
and after getting wrong results for a while I noticed that the results were in reverse order. Tried searching on cppreference 页面,但找不到任何来源,因此需要确认。这也应该是不同编译器的默认行为吗?
#include <iostream>
#include <bitset>
using namespace std;
int main() {
bitset<7> bin('C');
cout << bin << endl;
for(int i = 0; i < 7; ++i){ cout << bin[i]; }
return 0;
}
1000011
1100001
来自 C++ 标准:
When converting between an object
of class bitset<N>
and a value of some integral type, bit position pos corresponds to the bit value 1 << pos.
The integral value corresponding to two or more bits is the sum of their bit values.
我正在试用 std::bitset
and after getting wrong results for a while I noticed that the results were in reverse order. Tried searching on cppreference 页面,但找不到任何来源,因此需要确认。这也应该是不同编译器的默认行为吗?
#include <iostream>
#include <bitset>
using namespace std;
int main() {
bitset<7> bin('C');
cout << bin << endl;
for(int i = 0; i < 7; ++i){ cout << bin[i]; }
return 0;
}
1000011
1100001
来自 C++ 标准:
When converting between an object of class
bitset<N>
and a value of some integral type, bit position pos corresponds to the bit value 1 << pos. The integral value corresponding to two or more bits is the sum of their bit values.