【发布时间】:2017-04-27 12:27:22
【问题描述】:
所以我的模拟器有这段代码,可以将字节转换为十六进制
byteToHex(opcode) {
var tempCode = (opcode).toString(16).toUpperCase()
var addln = 4 - tempCode.length
var pad =""
for(var i = 0; i< addln; i++) {
pad = pad + "0"
}
var newCode = "0x"+ pad + tempCode
return newCode;
}
我有这个代码,它执行按位操作来获取操作码,然后将其转换以供使用。
this.opcode = (this.memory[this.pc] << 8) | this.memory[this.pc + 1]
console.log(this.memory)
console.log("before conversion", this.opcode)
this.opcode = this.byteToHex(this.opcode)
console.log(this.opcode)
//this just returns the first 'letter' of the opcode
switch (this.opcode & 0xF000)...
这是控制台输出
Array [ 240, 144, 144, 144, 240, 32, 96, 32, 32, 112, 70 more… ]
before conversion 0
0x0000
这意味着我获取的操作码不正确,但我不知道如何修复它。 为了更好地了解该项目:Github
【问题讨论】:
标签: javascript hex bit-manipulation emulation bitwise-operators