【发布时间】:2020-01-17 14:17:59
【问题描述】:
从以下链接 - https://gist.github.com/Romain-P/630f8565cd55b0c52314c47b509b9eb4
查看 ADD 部分 - 为什么他们从 op1[0],op2[1],op3[0] 中减去 48?我理解 or (|) 在左移后组合操作。 另外,为什么 chch 按位与 (&) 与 0x00ff?
else if (strcmp(token,"add")==0) //----------------- ADD -------------------------------
{
op1 = strtok(NULL,"\n\t\r ");
op2 = strtok(NULL,"\n\t\r ");
op3 = strtok(NULL,"\n\t\r ");
chch = (op1[0]-48)| ((op2[0]-48)<<3)|((op3[0]-48)<<6);
program[counter]=0x7000+((chch)&0x00ff);
counter++;
}
【问题讨论】:
-
48=='0'。这会将 ASCII 数字转换为 0 - 9 的范围。 -
48 是 '0' 的 ascii 代码
-
Anding 与
0x00ff获取变量的低字节。