0

I want to replicate in R these lines from c#:

uint m_z = 2169792120;
uint rg = m_z << 16; // rg = 1719140352

in R i tried this:

m_z = 2169792120
is.double(m_z) #TRUE
rg <- bitwShiftL(m_z, 16) #In bitwShiftL(a, 16) : NAs introduced by coercion to integer range
.Machine$integer.max < m_z #TRUE

bitwShiftL is for integer, what can i use if i need double?

vrige
  • 297
  • 1
  • 9
  • Do you really what to do a bit shift on the double? You wont get any sensible data out of this. What about converting it to an integer, then doing `bitwShiftL`? – BMI24 Jun 07 '20 at 10:10
  • can i really do it? m_z is bigger than the biggest integer(`.Machine$integer.max`) – vrige Jun 07 '20 at 10:11
  • `as.integer(m_z) # NAs introduced by coercion to integer range ` – vrige Jun 07 '20 at 10:15
  • 1
    I see. You could try using the int64 package ( https://stackoverflow.com/a/14589409/8512719 ). Or just multiply by 2^16 (which would be equivalent if you were using integers) – BMI24 Jun 07 '20 at 10:16
  • i will try with int64 package, but if i do 2^16 i get `142199496376320`. How do i get `1719140352` as in c#? i tried this: `142199496376320 %% 4294967295 #1719173460` where`4294967295` is tha maxvalue of `uint` in c# – vrige Jun 07 '20 at 10:31
  • I can't use package `int64` [link](https://cran.r-project.org/web/packages/int64/index.html). So i need to go with the second solution, but i still can't have `1719140352` as solution – vrige Jun 07 '20 at 10:38
  • 1
    Problem solved: it was `4294967296` and not `4294967295`. Thanks for help – vrige Jun 07 '20 at 10:44

0 Answers0