1. There are no unsigned integers in Java (all are signed and in "Big Endian").
2. X86系統使用Little Endian來儲存.
也就是說當Java Card 模擬器是run在x86平台上時,要注意兩者的轉換。
如果你在文件上看到一個雙字組的data,Ex: long MyData=0x12345678,要寫到從0x0000開始的記憶體位址時。
如果是Big Endian的系統,
存到記憶體會變成 0x12 0x34 0x56 0x78,最高位元組在位址最低位元,最低位元組在位址最高位元,依次排列。
如果是Little Endian的系統,
存到記憶體會變成 0x78 0x56 0x34 0x12,最低位元組在最低位元,最高位元組在最高位元,反序排列。
比較的結果就是這樣:
big-endian little-endian
0x0000 0x12 0x78
0x0001 0x34 0x56
0x0002 0x56 0x34
0x0003 0x78 0x12
這有什麼差別呢?
以目前常見的CPU為例:
INTEL X86、DEC VAX 使用 LITTLE-ENDIAN 設計;
HP、IBM、MOTOROLA 68K 系列使用 BIG-ENDIAN 設計;
POWERPC 同時支援兩種格式,稱為 BI-ENDIAN
參考:
http://www.prudentman.idv.tw/2007/11/big-endianlittle-endian.html
沒有留言:
張貼留言