Re: [Lazarus] reading a little endian long.
Mattias Gaertner wrote: On Mon, 22 Dec 2008 01:11:38 +0100 Marc Weustink m...@dommelstein.net wrote: Dave Coventry wrote: Wow. If I can push a little more: Can I read in an eight-byte IEEE double using the same trick? The example below is not complete, you need to cast. MyDouble:=LEtoN(PDouble(@buffer[5])^); Use codejumping (find declaration) on LEtoN to see what variants exist. AFAIK LEToN does not exist for double. You have to write one. Ok, then I've only looked at it and didn't implement. Marc ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
Is there any documentation on this? would the following: longv:=LEtoN(@buffer[5]); be the same as: longv:=buffer[5]; longv+=buffer[6] shl 8; longv+=buffer[7] shl 16; longv+=buffer[8] shl 24; 2008/12/21 Andrew Haines andrewd...@aol.com: Yes. See LEtoN, BEtoN, NtoLE and NtoBE. BlockRead(F, FooLongInt, 4); FooLongInt := LEtoN(FooLongInt); Regards, Andrew ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
On Sun, 21 Dec 2008 10:26:41 +0200 Dave Coventry dgcoven...@gmail.com wrote: Is there any documentation on this? would the following: longv:=LEtoN(@buffer[5]); longv:=LEtoN(PLongint(@buffer[5])^); be the same as: longv:=buffer[5]; longv+=buffer[6] shl 8; longv+=buffer[7] shl 16; longv+=buffer[8] shl 24; Mattias ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
Hi Mattias, Is there an equivalent for shortv:=buffer[5]; shortv+=buffer[6] shl 8; Many thanks Dave 2008/12/21 Mattias Gaertner nc-gaert...@netcologne.de: On Sun, 21 Dec 2008 10:26:41 +0200 Dave Coventry dgcoven...@gmail.com wrote: Is there any documentation on this? would the following: longv:=LEtoN(@buffer[5]); longv:=LEtoN(PLongint(@buffer[5])^); be the same as: longv:=buffer[5]; longv+=buffer[6] shl 8; longv+=buffer[7] shl 16; longv+=buffer[8] shl 24; Mattias ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
On Sun, 21 Dec 2008 12:04:37 +0200 Dave Coventry dgcoven...@gmail.com wrote: Hi Mattias, Is there an equivalent for shortv:=buffer[5]; shortv+=buffer[6] shl 8; shortv:=LEtoN(PSmallInt(@buffer[5])^); Mattias longv:=LEtoN(PLongint(@buffer[5])^); be the same as: longv:=buffer[5]; longv+=buffer[6] shl 8; longv+=buffer[7] shl 16; longv+=buffer[8] shl 24; ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
On Sun, Dec 21, 2008 at 6:26 AM, Dave Coventry dgcoven...@gmail.com wrote: Is there any documentation on this? http://www.freepascal.org/docs-html/rtl/system/index-5.html would the following: longv:=LEtoN(@buffer[5]); be the same as: No, it's better. It only performs a conversion from Little Endian to current encoding. So it will just copy the contents if your software is running in a little endian processor or do the adequate conversion if your software is running in a big endian processor. -- Felipe Monteiro de Carvalho ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
Wow. If I can push a little more: Can I read in an eight-byte IEEE double using the same trick? 2008/12/21 Felipe Monteiro de Carvalho felipemonteiro.carva...@gmail.com: On Sun, Dec 21, 2008 at 6:26 AM, Dave Coventry dgcoven...@gmail.com wrote: Is there any documentation on this? http://www.freepascal.org/docs-html/rtl/system/index-5.html would the following: longv:=LEtoN(@buffer[5]); be the same as: No, it's better. It only performs a conversion from Little Endian to current encoding. So it will just copy the contents if your software is running in a little endian processor or do the adequate conversion if your software is running in a big endian processor. -- Felipe Monteiro de Carvalho ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
Dave Coventry wrote: Wow. If I can push a little more: Can I read in an eight-byte IEEE double using the same trick? The example below is not complete, you need to cast. MyDouble:=LEtoN(PDouble(@buffer[5])^); Use codejumping (find declaration) on LEtoN to see what variants exist. Marc 2008/12/21 Felipe Monteiro de Carvalho felipemonteiro.carva...@gmail.com: On Sun, Dec 21, 2008 at 6:26 AM, Dave Coventry dgcoven...@gmail.com wrote: Is there any documentation on this? http://www.freepascal.org/docs-html/rtl/system/index-5.html would the following: longv:=LEtoN(@buffer[5]); be the same as: No, it's better. It only performs a conversion from Little Endian to current encoding. So it will just copy the contents if your software is running in a little endian processor or do the adequate conversion if your software is running in a big endian processor. -- Felipe Monteiro de Carvalho ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
On Mon, 22 Dec 2008 01:11:38 +0100 Marc Weustink m...@dommelstein.net wrote: Dave Coventry wrote: Wow. If I can push a little more: Can I read in an eight-byte IEEE double using the same trick? The example below is not complete, you need to cast. MyDouble:=LEtoN(PDouble(@buffer[5])^); Use codejumping (find declaration) on LEtoN to see what variants exist. AFAIK LEToN does not exist for double. You have to write one. Mattias ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
2008/12/22 Marc Weustink m...@dommelstein.net: The example below is not complete, you need to cast. MyDouble:=LEtoN(PDouble(@buffer[5])^); Use codejumping (find declaration) on LEtoN to see what variants exist. Marc Thanks Marc, I hadn't thought of doing that... Thanks to all the guys who have given me help on this; I wasn't sure that this list would be the best place to ask, but I was all googled out. ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
Dave Coventry wrote: If I Blockread(F,buffer,4) with buffer being an array of byte, Is there a routine in fpc/lazarus which will revers the bytes for me? This is what I want: longv:=buffer[0]; longv+=buffer[1] shl 8; longv+=buffer[2] shl 16; longv+=buffer[3] shl 24; Is there a function which does this for me? ___ Yes. See LEtoN, BEtoN, NtoLE and NtoBE. BlockRead(F, FooLongInt, 4); FooLongInt := LEtoN(FooLongInt); Regards, Andrew ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] reading a little endian long.
Great, thanks Andrew. 2008/12/21 Andrew Haines andrewd...@aol.com: Dave Coventry wrote: If I Blockread(F,buffer,4) with buffer being an array of byte, Is there a routine in fpc/lazarus which will revers the bytes for me? This is what I want: longv:=buffer[0]; longv+=buffer[1] shl 8; longv+=buffer[2] shl 16; longv+=buffer[3] shl 24; Is there a function which does this for me? ___ Yes. See LEtoN, BEtoN, NtoLE and NtoBE. BlockRead(F, FooLongInt, 4); FooLongInt := LEtoN(FooLongInt); Regards, Andrew ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus ___ Lazarus mailing list Lazarus@lazarus.freepascal.org http://www.lazarus.freepascal.org/mailman/listinfo/lazarus