Prev / Next

2015-08-15 / エンディアンを確認する

メモ

- Linux: How to tell if system is big endian or little endian? - Server Fault
  http://serverfault.com/questions/163487/linux-how-to-tell-if-system-is-big-endian-or-little-endian

$ echo -n I | od -to2 | head -n1 | cut -f2 -d" " | cut -c6


を実行し、

- 出力が 0 -> ビッグエンディアン
- 出力が 1 -> リトルエンディアン

ということらしい。


od の出力は以下の通り。

Solaris (SPARC)

$ echo -n I | od -to2 
0000000 044400
0000001


Solaris (x86)

$ echo -n I | od -to2
0000000 000111
0000001


左端は offset なので、'I' に相当するのは '044400' と '000111' の部分。
これを head -n1 | cut -f2 -d " " でとりだし、
cut -c6 で 6 文字目をとりだしている。

結果を利用せずに、目視で確認できればいい状況なら、
'12345' とかの適当な文字列を 16 進数で表示させるほうがわかりやすい。

Solaris (SPARC)

$ echo -n '12345' | od -tx
0000000 31323334 35000000
0000005


Solaris (x86)

$ echo -n '12345' | od -tx
0000000 34333231 00000035
0000005


comments powered by Disqus