What would be the easiest way to convert a number to base 2 (in a string, as for example 5 would be converted to "0000000000000101"
) in R? There is intToBits
, but it returns a vector of strings rather than a string:
> intToBits(12)
[1] 00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[26] 00 00 00 00 00 00 00
I have tried some other functions, but had no success:
> toString(intToBits(12))
[1] "00, 00, 01, 01, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00"