[R] Conversion to Binary (base2)
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Sep 25 22:03:50 CEST 2008
See also sfsmisc:as.intBase .
On Thu, 25 Sep 2008, Duncan Murdoch wrote:
> On 9/25/2008 3:33 PM, Jason Thibodeau wrote:
>> Is there a simple way to take an input, and convert the decimal integers to
>> binary? In this case, I have a CSV file, and I need to convert the first
>> column of every line to binary.
> Yes, the intToBits function does what you want. It works with raw vector
> output and integer vector input, so you need a few type conversions, but
> essentially this is simple:
>> x <- 123
>> paste(rev(as.integer(intToBits(as.integer(x)))), collapse="")
>  "00000000000000000000000001111011"
> Duncan Murdoch
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help