Re: [問題] big endian <-> little endian 轉換
※ 引述《sean72 (.)》之銘言:
: inline void endian_swap(unsigned short& x)
: {
: x = (x>>8) |
: (x<<8);
: }
假設 x = 0x ab cd
---------------------
x>>8 = 0x 00 ab
x<<8 = 0x cd 00
--------------------
| = 0x cd ab
似乎還蠻直覺的.
至於你原本的例子 x=12 有誤,乃因 x>>8 後應為 0,而你沒移到。
bit hacker 有些東西太艱澀, 確實不好懂.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 180.177.73.222
→
07/12 06:12, , 1F
07/12 06:12, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):