C言語でのエンディアンの変換
#TODO
C言語でエンディアン返還をする場合、
endian.h
とか
netinet/in.h
を使う。
ホストが
リトルエンディアン
で、endian.hを使う場合、
ビッグ→リトルなら
be32toh
とか
be16toh
リトル→ビッグなら
htobe32
とか
htobe16
code:c
#include
<stdio.h>
#include
<endian.h>
ソケット通信
系で使うやつの場合
code:c
#include
<netinet/in.h>
参考
Ubuntu Manpage: htobe16, htole16, be16toh, le16toh, htobe32, htole32, be32toh, le32toh, htobe64, htole64,
Ubuntu Manpage: htonl, htons, ntohl, ntohs - ホストバイトオーダーとネットワークバイトオーダーの間で値を変換する
関連
ソケット通信(C)