Am 19.10.2015 16:23 schrieb "Bo Berglund" <bo.bergl...@gmail.com>:
>
> On Mon, 19 Oct 2015 15:30:36 +0200 (CEST), Michael Van Canneyt
> <mich...@freepascal.org> wrote:
>
> >There are compiler defines that give you the endianness.
> >{$IFDEF ENDIAN_BIG}
> >{$IFDEF ENDIAN_LITTLE}
> >
> >And
> >{$IFDEF FPC_LITTLE_ENDIAN}
> >{$IFDEF FPC_BIG_ENDIAN}
>
> Good, that would probably be what I need. Thanks!
> Example:
>
> procedure Swap4 (var Source);
> {Swap the byte order of a 4-byte variable so it matches the PC i86}
> type
>     Reverse = packed record
>       B1 : Byte;
>       I2 : Word;
>       B4 : Byte;
>     end;
> var
>     Bsw : Byte;
> begin
>   {$IFDEF FPC_BIG_ENDIAN}
>     Bsw :=  Reverse(Source).B1;
>     Reverse(Source).B1 := Reverse(Source).B4;
>     Reverse(Source).B4 := Bsw;
>     Reverse(Source).I2 := Swap(Reverse(Source).I2);
>   {$ENDIF}
> end;
>
> Then all functions calling these functions could stay as they are and
> it will work on both the PC and Raspberry Pi2.
>
> Just have to make sure I don't have the endians reversed...
>

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).

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to