From: simon a. (B. <sim...@bb...> - 2005-11-29 13:54:22
|
On 29 Nov 2005, at 12:01, Andy Jones wrote: > Hi, > I=92m trying to convert data from various different instruments into=20= > mzData and I have a few questions. > =A0 > 1 One of the instruments produces plain text output for = the peak=20 > list (peak [tab] intensity). Does anyone have a script or some code=20 > for turning this into the mzData base 64 binary. Otherwise, any advice=20= > for how best to do this would be welcome. You didn't mention which language you were using to do your processing.=20= When I was decoding Base64 in Java I used this nice little (free)=20 library, which also does encoding. http://iharder.sourceforge.net/base64/ Before the Base64 encoding you'll need to convert your float/double=20 values to byte arrays (4 bytes per float or 8 bytes per double), then=20 encode the byte array. The Float and Double classes have built-in=20 methods to convert to int / long and then you just need to split these=20= down to their component bytes. eg for a float f, to get the 4 little endian bytes would be int i =3D Float.float.ToIntBits(f); byte [] bytes =3D new byte[4]; bytes[0] =3D (i & 0xFF); bytes[1] =3D (i >> 8) & 0xFF; bytes[2] =3D (i>>16) & 0xFF; bytes[3] =3D (i>>24) & 0xFF; You'd then encode this to get the string you include in the mzData file: String s =3D Base64.encodeBytes(bytes); Hope this helps Simon. --=20 Simon Andrews PhD Bioinformatics Dept. The Babraham Institute sim...@bb... +44 (0) 1223 496463 |