看板 C_and_CPP 關於我們 聯絡資訊
※ 引述《Schatze (吃哈吱)》之銘言: : 在一份文件上看到, : 長度123的句子, hex是7B, 所以長度只要用1byte, 0x7B來表示 : 長度1234的句子, hex是4D2, binary是0100 1101 0010 : 所以長度用2bytes, 0x89及0x52來表示. : 請問0x89及0x52是怎麼算出來的? : 謝謝 : 文件上這部份內容大概就只寫了這些, 之後接幾個範例 : TLV encoded : We are going to use the Tag-Length-Value system to encode the : tags that is used in EMV applications. : Encode the length as 1 byte with the highest bit to 1 if you need : more of 1 byte to encode it, or 0 if not. For instance, for the : length 123 (in hex it's 7B) the length is just 0x7B, but for the : length 1234 (in hex it's 4D2, in binary it's 0100 1101 0010) : it will be encoded as 0x89 in the first byte and 0x52 in the : second byte. 其實我也是看到問題時才 google TLV , 既 499 為誤,於此便不探討, 以下是我的「推測」,應拿其他數據實證為佳。 123 < 127 , 不擴, 123 = 0x7b , length = 0x7b 1234 > 127, 擴 1234(dec) = 0000 0100 1101 0010, 1 bytes = 7bits ^ ---------> 這個 1 要放到下一個 byte, 因它是 8th bit 0000 1001 0101 0010 , 再將 high bit 設 1 1000 1001 0101 0010 , 0x89 0x52 這樣,那個 499 = 0x01f3 = 0000 0001 1111 0011, 編完後變 1000 0011 0111 0011, 0x83 0x73, 若原作有給 499 怎麼編的話,請核對是否正確。 此部份沒實際跑過, 僅為推測, 待高人指點。 -- YouLoveMe() ? LetItBe() : LetMeFree(); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 180.177.73.222
Schatze:沒錯 就是如此! 謝謝您幫忙詳細解釋 我的表達能力不太好 06/20 15:32