Sean's Note

2009年9月28日 星期一

[C/C++] read in binary mode

如果想讀資料中每個 byte 的資料,下例看似正常沒什麼奇怪的。

Data : 42 4D 20 2A 3C 1A 42 43 ...

fp = fread(“data”, “r”);

c = fgetc(fp);

但這其實是錯的,當讀到 1A 時,後面接著讀的資料全都會變成 FFFFFFFF,

因為 1A 在 ASCII 裡代表的是 Substitue,也就是 Crtl + Z,

不知道程式讀到這裡的時候,是不是自己判斷暫停了?

最保險的方法還是加上 b 吧!

fp = fread(“data”, “rb”);


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