[R] Big-endian / Little-endian byte swap

From: Tuszynski, Jaroslaw W. <JAROSLAW.W.TUSZYNSKI_at_saic.com>
Date: Sat 21 May 2005 - 06:44:46 EST


Hi,

Is there a way to perform Big-endian / Little-endian byte swap in R?

An ugly way is by using readBin/writeBin:

	ByteSwap = function(X, size)
	{
	  writeBin(X, "tmp.dat")
	  readBin("tmp.dat", typeof(X), n = length(x), size=size,
endian="swap")
	}


> x = (1:5)*pi
> y = ByteSwap(x,8)
> z = ByteSwap(y,8)
> x
[1] 3.141593 6.283185 9.424778 12.566371 15.707963
> y
[1] 3.207376e-192 3.207376e-192 -4.277269e+87 3.207376e-192 7.596046e+145
> z
[1] 3.141593 6.283185 9.424778 12.566371 15.707963

But, there has to be some way of doing that without use of temporaty files.

Jarek

=====================================\====                 
 Jarek Tuszynski, PhD.                               o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                        ">  \
 Jaroslaw.W.Tuszynski@saic.com                   `    \



	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 21 06:52:21 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:59 EST