When I use std::bitset
this constructs a bitset and when I access it via the operator[]
, the bits seems to b
This is consistent with the way bits are usually numbered - bit 0 represents 20, bit 1 represents 21, etc. It has nothing to do with the endianness of the architecture, which concerns byte ordering not bit ordering.
There is no notion of endian-ness as far as the standard is concerned. When it comes to std::bitset
, [template.bitset]/3
defines bit position:
When converting between an object of class
bitset<N>
and a value of some integral type, bit positionpos
corresponds to the bit value1<<pos
. The integral value corresponding to two or more bits is the sum of their bit values.
Using this definition of bit position in your standard quote
initializing the first
M
bit positions to the corresponding bit values inval
a val
with binary representation 11
leads to a bitset<N> b
with b[0] = 1
, b[1] = 1
and remaining bits set to 0
.