...

/

Bit Manipulation

Bit Manipulation

Learn how to manipulate bits with the '<bit>' header.

The header <bit> supports functions to access and manipulate individual bits or bit sequences.

std::endian

Thanks to the new type std::endian, you get the endianness of a scalar type. Endianness can be big-endian or little-endian. Big-endian means that the most significant byte is the furthest left. Little-endian means that the least significant byte is furthest left. A scalar type is either an arithmetic type, an enum, a pointer, a member pointer, or a std::nullptr_t. The class endian provides the endianness of all scalar types:

Press + to interact
enum class endian
{
little = /*implementation-defined*/,
big = /*implementation-defined*/,
native = /*implementation-defined*/
};
  • If all scalar types are little-endian, std::endian::native is equal to std::endian::little.
  • If all scalar types are big-endian, std::endian::native is equal to std::endian::big. Even corner cases are supported:
  • If all scalar types have a size of 1 and therefore endianness does not matter, the values of the enumerators std::endian::little, std::endian::big, and std::endian::native are identical.
  • If the platform uses mixed endianness, std::endian::native is neither equal to std::endian::big nor std::endian::little.

When I run the following program on an ...