jeudi 5 février 2015

Unexpected result in ByteBuffer.js when writing a variable integer


Below, I'm trying to write out 0x16 as a variable integer. I'm expecting to see 0x2C, but instead I get 0x16. Any idea how I may adjust my use of ByteBuffer to get the expected result? Please follow the comments below:


http://ift.tt/1C3q0Nh



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


http://ift.tt/1D2uTHP


(btw: this is coffeescript, javascript without the parentheses)





Aucun commentaire:

Enregistrer un commentaire