【发布时间】:2020-11-14 21:55:18
【问题描述】:
在 c 语法中,我们可以移动有符号整数(负数):如果我们想强制和无符号整数移动,我们可以使用“>>>”。
y = -1732584194
(y>>16)
-26438
x = 1732584193
(x>>16)
26437
使用R,有位运算符https://stat.ethz.ch/R-manual/R-devel/library/base/html/bitwise.html
?bitwShiftL 例如显示相同的页面。它指出:“假设值表示无符号整数,则完成移位。”
y = -1732584194
bitwShiftR(y,16)
# [1] 39098 ## wanted -26438
x = 1732584193
bitwShiftR(x,16)
# [1] 26437 ## works as expected
展示如何使用 R 统计编程语言执行有符号移位?
【问题讨论】:
标签: r bit-manipulation bitwise-operators bit-shift 32-bit