// Decimal to binary
Function inttobin (value: longint; Size: integer): string;
VaR
I: integer;
Begin
Result: = '';
For I: = size-1 downto 0 do begin
If value and (1 shl I) <> 0 then begin
Result: = Result + '1 ';
End else begin
Result: = Result + '0 ';
End;
End;
End;
// Binary to decimal
Function bintoint (value: string): longint;
VaR
I, size: integer;
Begin
Result: = 0;
Size: = length (value );
For I: = size downto 1 do
Begin
If copy (value, I, 1) = '1' then
Result: = Result + (1 SHL (size-I ));
End;
End;
Function floatbintoint (value: string): real;
VaR
I, size: integer;
Begin
Result: = 0;
Size: = length (value );
For I: = size downto 1 do
Begin
If copy (value, I, 1) = '1' then
Result: = Result + 1/(1 shl I );
End;
End;
// Hexadecimal to binary
Function hextobinary (HEX: string): string;
Const
Box: array [0 .. 15] of string =
('123', '123', '123', '123 ',
'123', '123', '123', '123 ',
'123', '123', '123', '123 ',
'123', '123', '123', '123 ');
VaR
I: integer;
Begin
For I: = length (HEX) downto 1 do
Result: = Box [strtoint ('$' + hex [I])] + result;
End;
// Hexadecimal to decimal floating point
Function hextofloat (S: string): real;
VaR B, temp: string;
E: integer;
F: real;
Begin
B: = hextobinary (s );
Temp: = copy (B, 2, 8 );
E: = bintoint (temp)-127;
Temp: = copy (B, 10, 23 );
F: = 1 + floatbintoint (temp );
If (copy (B, 1, 1) = '0') then
Result: = power (2, e) * F
Else
Result: =-power (2, e) * F;
End;