Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-12

reading a little endian long.

13 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dave Coventry

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?

Reply by email

Andrew Haines
to Dave Coventry
Dave Coventry wrote 12 lines
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

Reply by email

Dave Coventry
to Andrew Haines

Great, thanks Andrew.

2008/12/21 Andrew Haines :

Show quoted text 27 lines
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 http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Dave Coventry
to Andrew Haines: Yes. See LEtoN, BEtoN, NtoLE and NtoBE. BlockRead(F, FooLongInt, 4); FooLongInt :=…

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 :

Show quoted text 14 lines
Yes. See LEtoN, BEtoN, NtoLE and NtoBE. BlockRead(F, FooLongInt, 4); FooLongInt := LEtoN(FooLongInt); Regards, Andrew _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mattias Gaertner
to Dave Coventry
Is there any documentation on this? would the following: longv:=LEtoN(@buffer[5]);
longv:=LEtoN(PLongint(@buffer[5])^);
Show quoted text 6 lines
be the same as: longv:=buffer[5]; longv+=buffer[6] shl 8; longv+=buffer[7] shl 16; longv+=buffer[8] shl 24;

Mattias

Reply by email

Dave Coventry
to Mattias Gaertner

Hi Mattias,

Is there an equivalent for

shortv:=buffer[5];
shortv+=buffer[6] shl 8;

Many thanks

Dave

2008/12/21 Mattias Gaertner :

Show quoted text 25 lines
On Sun, 21 Dec 2008 10:26:41 +0200 "Dave Coventry" 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 http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mattias Gaertner
to Dave Coventry
Show quoted text 6 lines
Hi Mattias, Is there an equivalent for shortv:=buffer[5]; shortv+=buffer[6] shl 8;
shortv:=LEtoN(PSmallInt(@buffer[5])^);

Mattias

Show quoted text 9 lines
> 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;

Reply by email

Felipe Monteiro de Carvalho
to Dave Coventry: Is there any documentation on this? would the following: longv:=LEtoN(@buffer[5]); be the…
Dave Coventry wrote
Is there any documentation on this?

http://www.freepascal.org/docs-html/rtl/system/index-5.html

Show quoted text 5 lines
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

Reply by email

Dave Coventry
to Felipe Monteiro de Carvalho

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 :

Show quoted text 23 lines
On Sun, Dec 21, 2008 at 6:26 AM, Dave Coventry 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 http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Marc Weustink
to Dave Coventry
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

Show quoted text 28 lines
2008/12/21 Felipe Monteiro de Carvalho : > On Sun, Dec 21, 2008 at 6:26 AM, Dave Coventry 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 > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mattias Gaertner
to Marc Weustink
Show quoted text 12 lines
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

Reply by email

Dave Coventry
to Marc Weustink: The example below is not complete, you need to cast.…

2008/12/22 Marc Weustink :

Show quoted text 8 lines
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.

Reply by email

Marc Weustink
to Mattias Gaertner: On Mon, 22 Dec 2008 01:11:38 +0100 AFAIK LEToN does not exist for double. You have to…
Mattias Gaertner wrote 17 lines
On Mon, 22 Dec 2008 01:11:38 +0100 Marc Weustink 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

Reply by email