0
下面,我試圖寫出0x16作爲變量整數。我期待看到0x2C,但我得到0x16。任何想法如何調整我使用ByteBuffer來獲得預期結果?請按照以下意見:寫入一個變量整數時,ByteBuffer.js出現意外的結果
http://jsfiddle.net/jslim180/h1ojuc54/
ByteBuffer = window.dcodeIO.ByteBuffer
b = new ByteBuffer(DEFAULT_CAPACITY=4, ByteBuffer.LITTLE_ENDIAN)
console.log '22 decimal is 0x16 hex: ' + (22).toString(16)
# 22 can be represented in less than 7 bits so the least significant bit
# should be 0 (indicating that no additional bytes are needed)
b.writeVarint32 22
b.printDebug() # Not expected: prints 0x16 .. this did not bitshift at all
# If I bit-shift manually, I get the expected result: 0x2C
console.log (0x16<<1).toString(16) # prints 2c
https://github.com/dcodeIO/ByteBuffer.js/wiki/API
(順便說一句:這是CoffeeScript的,沒有括號的JavaScript)