Skip to content
Prev 157192 / 398502 Next

Conversion to Binary (base2)

On 25/09/2008 4:22 PM, Jason Thibodeau wrote:
cat() adds a space between the things it outputs.  If you put sep="" 
you'll lose the space (or you could use collapse="" in the paste).

To reduce the number of bits to 17, just index the first 17 bits that 
intToBits gives you, or the last ones after the rev.

For example,

 > x <- 123
 > paste(rev(as.integer(intToBits(as.integer(x))[1:17])), collapse="")
[1] "00000000001111011"