Skip to content

Bytes to Numeric/Float conversion

6 messages · Bikash Agrawal, David Winsemius, Henrik Bengtsson +2 more

#
On Jun 11, 2013, at 9:01 AM, Bikash Agrawal wrote:

            
There is a raw data type that is designed to hold bytes than can be indexed.

?raw

`scan` can read files of type raw

?scan
#
On Tue, Jun 11, 2013 at 2:14 PM, David Winsemius <dwinsemius at comcast.net> wrote:
...and then ?readBin

/Henrik
#
I recommend the hexView package for setting up such conversions.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.
David Winsemius <dwinsemius at comcast.net> wrote:

            
#
On 13-06-12 6:54 AM, Bikash Agrawal wrote:
If you want exact transfer from bytes, use raw connections.  For example:

 > con <- rawConnection(raw(0), "r+")
 > writeBin(pi, con)
 > rawConnectionValue(con)
[1] 18 2d 44 54 fb 21 09 40
 > seek(con,0)
[1] 8
 > readBin(con, "numeric")
[1] 3.141593

Depending on how you created the bytes, you may need to do some fiddling 
with the optional parameters size and endian of readBin to read them 
properly.

Duncan Murdoch