<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Here is a very simple conversion from a dynamic 
byte array to a Single:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>function BytesToSingle(Data: 
TByteDynArray;<BR>&nbsp; Position: Integer): 
Single;<BR>{-------------------------------------------------------------------------<BR>&nbsp;DESCRIPTION:&nbsp; 
Accepts a byte array and returns a Single.<BR>&nbsp;PARAMETERS:&nbsp;&nbsp; The 
byte array and an integer specifying the position in the array to 
start.<BR>&nbsp;RETURNS:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Single<BR>-------------------------------------------------------------------------}<BR>const<BR>&nbsp; 
DATA_SIZE: Longint = 4;<BR>begin<BR>&nbsp; if Position &lt;= High(Data) - 
(DATA_SIZE - 1) then<BR>&nbsp;&nbsp;&nbsp; Move(Data[Position], result, 
DATA_SIZE);<BR>end;<BR></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>And a routine to convert from a Single to 
Bytes:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>function SingleToBytes(Data: Single): 
TByteDynArray;<BR>{---------------------------------------------------------------------------<BR>&nbsp;&nbsp; 
DESCRIPTION:&nbsp;&nbsp;&nbsp; Converts the Single to a 4byte 
array.<BR>&nbsp;&nbsp; PARAMETERS:&nbsp;&nbsp;&nbsp;&nbsp; 
Data&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The Single to 
convert<BR>&nbsp;&nbsp; RETURNS:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
TByteDynArray&nbsp; The byte values separated into a byte 
array<BR>---------------------------------------------------------------------------}<BR>const<BR>&nbsp; 
DATA_SIZE : LongInt = 4;<BR>begin<BR>&nbsp; SetLength(result, 
DATA_SIZE);<BR>&nbsp; Move(Data, result[0], DATA_SIZE);<BR>end;<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>The above routine could also easily be adapted to 
work with an existing byte array and take a&nbsp;pPosition parameter like the 
first routine.</DIV></FONT>
<DIV><FONT face=Arial size=2>&nbsp;</DIV></FONT>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A title=colmin@ihug.co.nz href="mailto:colmin@ihug.co.nz">Colin/Mina</A> 
  </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A title=Delphi@delphi.org.nz 
  href="mailto:Delphi@delphi.org.nz">Delphi@delphi.org.nz</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, August 31, 2004 9:29 
  PM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> [DUG] RE: [DUG-Offtopic] Byte to 
  Real conversion</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=Arial size=2>Hi,</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>Any ideas please?</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>I am developing an embedded processor controller 
  that&nbsp;needs to&nbsp;continuously communicate&nbsp;data over a&nbsp;link to 
  another. The baud rate is limited to 9600 Bd. The numeric range of each data 
  packet will need to be at least +/ 12 digits. I am concerned that the time 
  taken to send this data may too high if sent as strings of characters and I 
  would like to limit this.</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>My data&nbsp;values could be&nbsp;easily 
  represented within the four bytes of a 'Single' which is the smallest Real 
  type and would give me a range of </FONT><FONT face=Arial size=2>1.5 x 10 ^-45 
  .. 3.4 x 10 ^38. This being the case I could send the data&nbsp;as 4 x 
  char(bytes) + a checksum and terminator.</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>My question is - What is the simplest way of 
  doing the conversion in each direction. <FONT face=Arial size=2>I have to deal 
  with two different microprocessors, but&nbsp;t</FONT></FONT><FONT face=Arial 
  size=2>he&nbsp;maths libraries I have in the compilers are not too bad. I've 
  had a play but seem to be getting into problems with type casting.&nbsp; A 
  Pascal demo would be a great help.</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>Regards</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2>&nbsp; Colin</FONT></DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
  <P>
  <HR>

  <P></P>_______________________________________________<BR>Delphi mailing 
  list<BR>Delphi@ns3.123.co.nz<BR>http://ns3.123.co.nz/mailman/listinfo/delphi<BR></BLOCKQUOTE></BODY></HTML>