binary literal representation

I have a table of bit masks (for aircraft identification purposes, in case you are curious).
Something like:

state_block <- tribble(
  ~state,      ~num_addr, ~mask,
  "Afghanistan",            4096, 011100000000,
  "Albania",                1024, 01010000000100,
  "Algeria",               32768, 000010100,
  "Angola",                 4096, 000010010000,
  "Antigua and Barbuda",    1024, 00001100101000
  # 185 more
}

The mask column is about the initial pattern of a 24 bit aircraft address.

Is there in R a literal representation for integers in binary form, something like 0b101 in Java or C++14?
And if not, any suggestions as how to proceed (i.e. define a custom type?)?
Thanks!

1 Like

You can mutate column ~mask as a character representation of a binary digit and then coerce it back to a long integer

library(bit64)
library(compositions)
# convert integer to a character representation of a binary digit
b <- binary(4096)
b
#[1] "1000000000000"
 
# convert character representation of a binary digit to a long integer
b_li <- as.integer64(b)
b_li
integer64
1000000000000
2 Likes