最終更新日時(UTC):
が更新

履歴 編集

function template
<bit>

std::byteswap(C++23)

namespace std {
  template <class T>
  constexpr T byteswap(T value) noexcept;
}

概要

valueのオブジェクト表現に対してバイト単位で逆順並び替え(エンディアン変換)を行う。

テンプレートパラメータ制約

Tintegralのモデルであること

適格要件

Tがパディングビットを含まないこと

戻り値

valueのオブジェクト表現をバイト単位で逆順に並び替えた整数型Tの値を返す。

例外

投げない

#include <bit>
#include <format>
#include <iostream>

int main()
{
  std::uint32_t src = 0x12345678u;
  std::cout << std::format("{:x}", src) << std::endl;

  std::uint32_t dst = std::byteswap(src);
  std::cout << std::format("{:x}", dst) << std::endl;
}

出力

12345678
78563412

バージョン

言語

  • C++23

処理系

参照