https://mp.weixin.qq.com/s?__biz=MzUyNzMwMTAwNw==&mid=2247483736&idx=1&sn=247c204880bde06eda8b77fd14e4d93a&chksm=fa00e1b8cd7768aee094020746eda244b26f2bb78332e8c68257f80d7966ed1ba82ed23dfe23&scene=21#wechat_redirect
順便學習了一些程式編碼問題與複習(雖然這篇後段完全看不懂...)
首先先看這篇,先了解原碼、反碼、補碼
http://www.cnblogs.com/en-heng/p/5570609.html
然後 裡面有計算ZigZag
根據int 編碼
h(n) = (n << 1) ^ (n >> 31)
依照範例 數值 1,-1來練習
if n=1;
original code=0,0000000000,0000000000,0000000000,1
n<<1=
0,0000000000,0000000000,0000000001,0
n>>31=
0,0000000000,0000000000,0000000000,0
(n << 1) ^ (n >> 31)
^ => 0,0=0 1,0=1 0,1=1 1,1=0
so =
0,0000000000,0000000000,0000000001,0
Decimal=2
---------------------------------------------------------------
if n=-1;
original code=1,0000000000,0000000000,0000000000,1
反碼=1,1111111111,1111111111,1111111111,0
補碼=
1,1111111111,1111111111,1111111111,1
n<<1=
1,1111111111,1111111111,1111111111,0
n>>31=
1,1111111111,1111111111,1111111111,1
(n << 1) ^ (n >> 31)
^ => 0,0=0 1,0=1 0,1=1 1,1=0
so =
0,0000000000,0000000000,0000000000,1
Decimal=1