2015年2月12日 星期四
linux 網路設定
| 修改的參數 | 設定檔與重要啟動腳本 | 觀察結果的指令 |
| IP相關參數 | /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/init.d/network restart | ifconfig (IP/Netmask) route -n (gateway) |
| DNS | /etc/resolv.conf | dig www.google.com |
| 主機名稱 | /etc/sysconfig/network /etc/hosts | hostname (主機名) ping $(hostname) reboot |
2015年2月11日 星期三
2015年2月10日 星期二
c/c++ 演算法技巧
今天看code 看到一個莫名其妙的東西,上網搜尋一下
unsigned popcount (unsigned u)
{
u = (u & 0x55555555) + ((u >> 1) & 0x55555555);
u = (u & 0x33333333) + ((u >> 2) & 0x33333333);
u = (u & 0x0F0F0F0F) + ((u >> 4) & 0x0F0F0F0F);
u = (u & 0x00FF00FF) + ((u >> 8) & 0x00FF00FF);
u = (u & 0x0000FFFF) + ((u >> 16) & 0x0000FFFF);
return u;
}
原來是個不知為何的演算法得出來的結果,原理大概是查表,此用法只適用於32位無號整數,目的是在算input u 總共有幾個bit為1,稍微紀錄一下。
=> 使用分治法
https://zh.wikipedia.org/wiki/%E6%B1%89%E6%98%8E%E9%87%8D%E9%87%8F
簡單來說就是先算出兩個bit裡面有幾個1
A=b'1111
(A) &(b'0101) +(A>>1)&(b'0101) =b'1010
代表第
0,1 bit 有兩個為1
2,3bit 有兩個為1
接著就是 shift跟加法的問題
ref.
http://blog.csdn.net/rappy/article/details/1788969
unsigned popcount (unsigned u)
{
u = (u & 0x55555555) + ((u >> 1) & 0x55555555);
u = (u & 0x33333333) + ((u >> 2) & 0x33333333);
u = (u & 0x0F0F0F0F) + ((u >> 4) & 0x0F0F0F0F);
u = (u & 0x00FF00FF) + ((u >> 8) & 0x00FF00FF);
u = (u & 0x0000FFFF) + ((u >> 16) & 0x0000FFFF);
return u;
}
=> 使用分治法
https://zh.wikipedia.org/wiki/%E6%B1%89%E6%98%8E%E9%87%8D%E9%87%8F
簡單來說就是先算出兩個bit裡面有幾個1
A=b'1111
(A) &(b'0101) +(A>>1)&(b'0101) =b'1010
代表第
0,1 bit 有兩個為1
2,3bit 有兩個為1
接著就是 shift跟加法的問題
ref.
http://blog.csdn.net/rappy/article/details/1788969
2015年1月21日 星期三
How many bytes in a packet?
Sometime, we found some devices that point out "forwarding rate, Mpps". The "pps" is the short term for packet per second. However, how many bytes in a packet? It depends, there is no specification on how many byte in a packet, you define it by yourself.
In the 100M Ethernet network,
100M bps / 8 = 12.5 MBps = 12500000 Bytes/s(Bps)
If you define the frame size is 64 Bytes (Minimum Ethernet framz size):
8 Bytes (preamble) + 64 Bytes + 12 Bytes (interframe gap) = 84 Bytes
So forwarding rate will be
12500000 Bps / 84 bytes = 148809 pps
If you define the frame size is 1518 Bytes (Maximum Ethernet framz size):
8 Bytes (preamble) + 1518 Bytes + 12 Bytes (interframe gap) = 1538 Bytes
So forwarding rate will be
12500000 Bps / 1538 bytes = 8127 pps
100M Ethernet's forwarding rate formula:
12500000 Bps / ( 8 Bytes (preamble) + (Feame Size) + 12 Bytes (interframe gap)) = forwarding rate, pps
In the 100M Ethernet network,
100M bps / 8 = 12.5 MBps = 12500000 Bytes/s(Bps)
If you define the frame size is 64 Bytes (Minimum Ethernet framz size):
8 Bytes (preamble) + 64 Bytes + 12 Bytes (interframe gap) = 84 Bytes
So forwarding rate will be
12500000 Bps / 84 bytes = 148809 pps
If you define the frame size is 1518 Bytes (Maximum Ethernet framz size):
8 Bytes (preamble) + 1518 Bytes + 12 Bytes (interframe gap) = 1538 Bytes
So forwarding rate will be
12500000 Bps / 1538 bytes = 8127 pps
100M Ethernet's forwarding rate formula:
12500000 Bps / ( 8 Bytes (preamble) + (Feame Size) + 12 Bytes (interframe gap)) = forwarding rate, pps
2015年1月9日 星期五
c/c++ 運算子優先順序
優先 符號 運算種類 結合
---- ---------------------- ------------- ------
1 (
) [ ] -> . 運算式 左至右
2 !
~ ++ -- - (運算元) 一元運算子 右至左
*
& sizeof
3 *
/ % 乘/除/餘數 左至右
4 +
- 加/減 左至右
5 <<
>> 左移/右移 左至右
6 <
<= > >= 關係運算子 左至右
7 ==
!= 關係運算子 左至右
8 & 位元 AND 左至右
9 ^
位元 XOR 左至右
10 |
位元 OR 左至右
11 &&
邏輯 AND 左至右
12 || 邏輯 OR 左至右
13 ?:
條件運算子 右至左
14 =
+= -= *= /= %= 指定運算子 右至左
<<=
>>= &= |= ^=
15 ,
循序計值 左至右
2015年1月8日 星期四
SVN externals 屬性 依賴 外部連結
快速
http://blog.csdn.net/echoisland/article/details/6584875
詳細
https://cylin.wordpress.com/2007/10/08/svnexternals%E5%B1%AC%E6%80%A7%E4%B9%8B%E4%BD%BF%E7%94%A8/
//windows 操作
http://ccd9527.blogspot.tw/2010/06/svnexternals.html
https://help.cloudforge.com/entries/22483742-Setting-up-svn-externals
原文
http://svnbook.red-bean.com/nightly/en/svn.advanced.externals.html
http://blog.csdn.net/echoisland/article/details/6584875
詳細
https://cylin.wordpress.com/2007/10/08/svnexternals%E5%B1%AC%E6%80%A7%E4%B9%8B%E4%BD%BF%E7%94%A8/
//windows 操作
http://ccd9527.blogspot.tw/2010/06/svnexternals.html
https://help.cloudforge.com/entries/22483742-Setting-up-svn-externals
原文
http://svnbook.red-bean.com/nightly/en/svn.advanced.externals.html
訂閱:
文章 (Atom)