以十六进制打印大数 [英] Print big number in hexadecimal

查看:27
本文介绍了以十六进制打印大数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将大数转换为 R 中的十六进制表示,但它失败了,因为它无法放入 32 位整数.有什么办法可以克服这个限制吗?

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

推荐答案

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

Luckily I found the solution, but requires library gmp

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

这篇关于以十六进制打印大数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆