如何在R中转换64位十六进制字符串? [英] How do I convert 64-bit hexadecimal strings in R?
本文介绍了如何在R中转换64位十六进制字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在R中转换64位十六进制字符串?
How do I convert 64-bit hexadecimal strings in R?
> library(int64)
> as.int64("7f2d36a2a000")
[1] NA
Warning message:
In as.int64("7f2d36a2a000") : NAs introduced
> as.int64("0x7f2d36a2a000")
[1] NA
Warning message:
In as.int64("0x7f2d36a2a000") : NAs introduced
推荐答案
对于大数字,您需要加载一个支持任意大数字表示形式的程序包. Rmpfr 是一个示例:
For a number that large, you'll need to load a package that supports representations of arbitrarily large numbers. Rmpfr is one example:
library(Rmpfr)
## Check that it works as expected on smaller numbers:
strtoi("ff", base=16)
# [1] 255
mpfr("ff", base=16)
# 1 'mpfr' number of precision 8 bits
# [1] 255
as.integer(mpfr("ff", base=16)
# [1] 255
## Then apply it with (more) confidence to larger numbers:
mpfr("7f2d36a2a000", base=16)
# 1 'mpfr' number of precision 48 bits
# [1] 139832166883328
mpfr("7f2d36a2a0007f2d36a2a0007f2d36a2a0007f2d36a2a000", base=16)
# 1 'mpfr' number of precision 192 bits
# [1] 3118361524223520784583964884878580812558070356334996529152
这篇关于如何在R中转换64位十六进制字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文