2014-10-10 10 views
4

R에서 64 비트 16 진수 문자열을 변환하려면 어떻게해야합니까?R에서 64 비트 16 진수 문자열을 변환하려면 어떻게해야합니까?

> 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 
+2

CRAN에서 제거 된 고아 패키지입니다. bit64 고려 : http://cran.r-project.org/web/packages/bit64/index.html 또는 Rmpfr : http://cran.r-project.org/web/packages/Rmpfr/index.html –

답변

3

큰 숫자의 경우 임의로 큰 숫자의 표현을 지원하는 패키지를로드해야합니다.

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 
5

여기 bit64를 사용하는 방법이있다 : Rmpfr 한 예이다.

library(bit64) 
str <- "7f2d36a2a000" 
as.integer64(as.numeric(paste0("0x",str))) 
# integer64 
[1] 139832166883328