Sean's Note

2009年4月14日 星期二

[C/C++] 更改變數的位元值

假設 int a = 0xFFFFFFF1,

 
想要將 3rd bit 設成 1,且不更動到其他 bits 的值,該怎麼用 C 來寫呢?
 
其實只要用 CLEAR 和 OR 就可以達成,什麼語言都一樣,
 
int MASK = 0x04;  // 3rd bit is what we choose
 
a &= ~MASK;  // CLEAR bit
 
a |= MASK;     //  SET bit
 
最後,
 
a = 0xFFFFFFF5
 
就是我們要結果啦!


2008年12月22日 星期一

數字拼圖

數字拼圖 (33.5KB)

禮拜天無聊的時候寫的.
排成這樣就贏了(用滑鼠點選) :
5   2   8            1   2   3
7   3   1    ->     4   5   6
4   6                 7   8




2008年11月9日 星期日

貪食蛇 Snakii

Snakii V1.1 (235KB)

之前有做過 console 版本的, 不過 code 不見了 @@
所以這次又重寫了一個視窗版的.
畫面很陽春啦, 自己畫圖超累的 XD
Bug1. 因為障礙物是隨機產生的, 如果障礙把水果圍住, Snakii 就吃不到了.
雖然機率應該很低, 不過有空還是要解決一下這個問題.


V1.1 更新內容 :
1. 更新背景
2. 一開始不容易撞到石頭


V1.0 更新內容 :
1. 初版




2008年10月6日 星期一

Four Bits Adder

兩個 half adder 合成一個 full adder, 四個 full adder 合成一個 4 bits adder.

想畫美美的圖用 PhotoImpact 就對了, PhotoImpact 真好用阿. 

從國一用到現在的軟體, 作業報告網頁的圖片都靠它了.

要支持國產貨!  哈哈.


2008年8月28日 星期四

Where Are Windows Vista Cookies !?

The Enigmatic Cookies Folder In Vista
Type Cookies in Start Menu. and it may take you to C:\Users\Username\cookies folder. When you try to click on it, in all probability, you will be greeted with an Access Denied box. This path, however, is just a kind of a pointer.
To see where IE 7 stores its Cookies in Windows Vista :
Open Explorer > Organize > Folder Options > Views > Check 'Do not show hidden files and folders' and Uncheck 'Hide protected OS files' > Apply > OK.
Now you will be able to see the two real locations of Vista's Cookies folders.
C:\Users\username\AppData\Roaming\Microsoft\Windows\Cookies C:\Users\username\AppData\Roaming\Microsoft\Windows\Cookies\Low
As mentioned elsewhere on this site, in Vista, processes run with integrity levels as defined by the Mandatory Integrity Control Feature. 'Protected Mode' Internet Explorer, runs as a 'Low Privilege' process. This prevents the Internet Explorer from writing to areas of the File System or the Registry that require a higher privilege! What happens, is that, Vista creates a set of folders and files, for use with Protected Mode' Internet Explorer. These folders and files share the same Low Privilege level as Internet Explorer.
One of these 4 'low privilege' folders, used by IE7 in Vista, in the course of daily operation, is Cookies, the other being Cache, History & Temp, and is located at:
%AppData%\Microsoft\Windows\Cookies\Low
With the IE 7 Protected Mode Turned On, the browser essentially runs as a low privilege process; as a result of which it can store / read / write cookies in the LOW version of the Cookies folder:
C:\Users\username\AppData\Roaming\Microsoft\Windows\Cookies\Low
But if you have turn UAC off or Disabled the Protected Mode in IE 7, in Windows Vista, they (like cache, temp & history) will mostly be stored in:
C:\Users\username\AppData\Roaming\Microsoft\Windows\Cookies
以上內容源自 : winvistaclub 

2008年8月2日 星期六

[PHP] 中文編碼 " 許功蓋 " 和 " ' "

如果有使用到讓使用者輸入文字的表格,

使用者輸入"許功蓋" 時, 資料庫裡存的會是"許\功\蓋\"

只要加上下面這一行就可以了.


$str = stripslashes($str);

另外使用者如果輸入 " ' " 的時候, PHP 的 query 會出現錯誤訊息,

將一個 '  取代成兩個 '' 就行了, 如下.


$str = str_replace("'", "''", $str);