[R] Output of binary representation
(Ted Harding)
Ted.Harding at manchester.ac.uk
Sun May 17 19:23:52 CEST 2009
I am interested in studying the binary representation of numerics
(doubles) in R, so am looking for possibilities of output of the
internal binary representations. sprintf() with format "a" or "A"
is halfway there:
sprintf("%A",pi)
# [1] "0X1.921FB54442D18P+1"
but it is in hex.
The following illustrate the sort of thing I want:
1.1001 0010 0001 1111 1011 0101 0100 0100 0100 0010 1101 0001 1000
times 2
11.0010 0100 0011 1111 0110 1010 1000 1000 1000 0101 1010 0011 000
0.1100 1001 0000 1111 1101 1010 1010 0010 0010 0001 0110 1000 1100 0
times 4
(without the spaces -- only put in above for clarity).
While I could take the original output "0X1.921FB54442D18P+1" from
sprintf() and parse it out into binary using gsub() or the like,
of submit it to say an 'awk' script via an external file, this would
be a tedious business!
Is there some function already in R which outputs the bits in the
binary representation directly?
I see that Dabid Hinds asked a similar question on 17 Aug 2005:
"Raw data type transformations"
http://finzi.psych.upenn.edu/R/Rhelp02/archive/59900.html
(without, apparently, getting any response -- at any rate within
the following 3 months).
With thanks for any suggestions,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 17-May-09 Time: 18:23:49
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list