Here are two tricks that avoid evil casting and maintain strict type checking :-)

var
 L : longword;
 A : array [0..7] of byte; absolute L;

Now just store what you want in L and read from A or vice versa.



There is yet another way

type
 Seq = packed record
   case boolean of
     false : (L : longword);
     true  : (B0,B1,B2,B3,B4,B5,B6,B7 : byte)
 end;

var
 X : Seq;

X.L := $12345678;
B := X.B0;

etc




Donovan J. Edye wrote:


G'Day,

I need to take any number and encode it as a sequence of bytes, and then
given a known sequence of bytes convert it into a number once more. So
basically

Anumber : longword --> AbyteArray : array of byte
AbyteArray : array of byte --> Anumber : longword

This is simple I am sure..... ;-)

Any code snippets greatly appreciated.

TIA

-- Donovan J. Edye
----------------------------------------------------------------------
Namadgi Systems
Voice: +61-2-6285-3460
Fax: +61-2-6285-3459
----------------------------------------------------------------------
SetiStats - Get your SETI statistics delivered to your mailbox daily.
http://www.edye.wattle.id.au/p.php?page=/delphi/setistats
<http://www.edye.wattle.id.au/p.php?page=/delphi/setistats> ----------------------------------------------------------------------







---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to