I am running the code below in R, and it doesn't return the original decimal number.
as.hexmode(-8192)
"ffffe000"
strtoi(c("ffffe000"))
NA
My book says the hexadecimal notation FFFF equals 65535 in decimal value.
The strtoi
function takes a string as an input (see docs). However, the as.hexmode
function does not return an integer but rather a hexadecimal representation of the input, which is not a string (it is a type named hexmode
AFAIK).
The proper solution, as suggested by the R documentation, is using as.integer
to obtain your original input:
> strtoi(as.hexmode(-8192),16)
[1] NA
> as.integer(as.hexmode(-8192))
[1] -8192
It remains unclear to me whether the problem is with using a negative input. I can only suppose strtoi
handles only unsigned ints.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With