<p>Am 19.10.2015 16:23 schrieb "Bo Berglund" <<a href="mailto:bo.berglund@gmail.com">bo.berglund@gmail.com</a>>:<br>
><br>
> On Mon, 19 Oct 2015 15:30:36 +0200 (CEST), Michael Van Canneyt<br>
> <<a href="mailto:michael@freepascal.org">michael@freepascal.org</a>> wrote:<br>
><br>
> >There are compiler defines that give you the endianness.<br>
> >{$IFDEF ENDIAN_BIG}<br>
> >{$IFDEF ENDIAN_LITTLE}<br>
> ><br>
> >And<br>
> >{$IFDEF FPC_LITTLE_ENDIAN}<br>
> >{$IFDEF FPC_BIG_ENDIAN}<br>
><br>
> Good, that would probably be what I need. Thanks!<br>
> Example:<br>
><br>
> procedure Swap4 (var Source);<br>
> {Swap the byte order of a 4-byte variable so it matches the PC i86}<br>
> type<br>
> Reverse = packed record<br>
> B1 : Byte;<br>
> I2 : Word;<br>
> B4 : Byte;<br>
> end;<br>
> var<br>
> Bsw : Byte;<br>
> begin<br>
> {$IFDEF FPC_BIG_ENDIAN}<br>
> Bsw := Reverse(Source).B1;<br>
> Reverse(Source).B1 := Reverse(Source).B4;<br>
> Reverse(Source).B4 := Bsw;<br>
> Reverse(Source).I2 := Swap(Reverse(Source).I2);<br>
> {$ENDIF}<br>
> end;<br>
><br>
> Then all functions calling these functions could stay as they are and<br>
> it will work on both the PC and Raspberry Pi2.<br>
><br>
> Just have to make sure I don't have the endians reversed...<br>
></p>
<p>You don't need to implement this yourself. Just use NToBe when transmitting to the Motorola unit and BeToN when receiving from it. Both functions provide overloads for the usual sizes (see the documentation link provided by Jonas).</p>
<p>Regards,<br>
Sven</p>