以十六进制打印大数字

时间:2015-03-18 23:03:41

标签: r string-formatting

我试图在R中将大数字转换为十六进制表示,但它失败了,因为它不能适应32位整数。有没有办法克服这个限制?

> print(0xffffffff+0x10000000)
[1] 4563402751
> as.hexmode(0xffffffff+0x10000000)
Error in if (is.double(x) && (x == as.integer(x))) x <- as.integer(x) : 
  missing value where TRUE/FALSE needed
In addition: Warning message:
In as.hexmode(4294967295 + 268435456) : NAs introduced by coercion

1 个答案:

答案 0 :(得分:3)

幸运的是我找到了解决方案,但需要库gmp

library(gmp)
> as.character(as.bigz(0xffffffff+0x10000000),b=16)
[1] "10fffffff"