下面,我尝试写出0x16作为一个变量整数。我期望看到0x2C,但是我得到0x16。你知道我该如何调整ByteBuffer的使用来获得预期的结果吗?请关注下面的评论:
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 2chttps://github.com/dcodeIO/ByteBuffer.js/wiki/API
(顺便说一下:这是coffeescript,不带括号的javascript )
发布于 2015-02-06 04:30:44
ByteBuffer正在写出无符号变量。我需要使用writeVaruint32。https://github.com/dcodeIO/ByteBuffer.js/issues/44
https://stackoverflow.com/questions/28351493
复制相似问题