首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >写入变量整数时在ByteBuffer.js中出现意外结果

写入变量整数时在ByteBuffer.js中出现意外结果
EN

Stack Overflow用户
提问于 2015-02-06 02:35:14
回答 1查看 272关注 0票数 1

下面,我尝试写出0x16作为一个变量整数。我期望看到0x2C,但是我得到0x16。你知道我该如何调整ByteBuffer的使用来获得预期的结果吗?请关注下面的评论:

http://jsfiddle.net/jslim180/h1ojuc54/

代码语言:javascript
复制
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 )

EN

回答 1

Stack Overflow用户

发布于 2015-02-06 04:30:44

ByteBuffer正在写出无符号变量。我需要使用writeVaruint32。https://github.com/dcodeIO/ByteBuffer.js/issues/44

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28351493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档