C++ はビット順序について何か言いますか? 私は特にプロトコル パケット レイアウトに取り組んでおり、特定の数値をビット 5、6、7 (ビット 5 が「最上位」) に書き込むように指定する移植可能な方法があるかどうか疑問に思っています。
私の質問:
- 0x01 は常にビット 7 が設定されたバイトとして表されますか?
- は
bitset<8>().set(7).to_ulong()
常に 1 ですか?
C++ はビット順序について何か言いますか? 私は特にプロトコル パケット レイアウトに取り組んでおり、特定の数値をビット 5、6、7 (ビット 5 が「最上位」) に書き込むように指定する移植可能な方法があるかどうか疑問に思っています。
私の質問:
bitset<8>().set(7).to_ulong()
常に 1 ですか?If the question is whether you can happily ignore endianness of the platform while sending binary objects over the network, the answer is you cannot. If the question is whether the same code compiled in two different platforms will yield the same results, then the answer is yes.