Skip to content
Prev 325225 / 398503 Next

Bytes to Numeric/Float conversion

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