Print big number in hexadecimal

社会主义新天地 提交于 2019-12-20 03:03:58

问题


I'm trying to convert big number to hexadecimal representation in R, but it fails, because it can't fit into 32-bit integer. Is there any way to overcome this limitation?

> 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:


Luckily I found the solution, but requires library gmp

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


来源:https://stackoverflow.com/questions/29134321/print-big-number-in-hexadecimal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!