PDA

View Full Version : Extended precision conversion



masonwheeler
29-09-2007, 09:13 PM
Does anyone know where I can find a webpage (or download a program) that does what this page (http://www.rit.edu/~meseec/eecc250-winter99/IEEE-754hex32.html) does, but works with 80-bit extended-precision values? I'm trying to trace my way through an algorithm I found in a program I decompiled, but it doesn't do me much good unless I can figure out what the numbers being used are.

Mason

JSoftware
29-09-2007, 10:56 PM
what do you need? do you need to calculate an extended value from a hex string?

or find the mantissa, exponent and sign?

masonwheeler
29-09-2007, 11:00 PM
Calculate the value, in human-readable numbers, from a hex string. (I'd like to be able to input "F5 3A ... whatever" and have it come up with "1.5" or "29.831" or somesuch result.)

Mason

Brainer
30-09-2007, 08:38 AM
So you want to convert a hex value into a decimal number, right? If so, here is a program from my favourite Pascal book (sorry for unformatted code):

{
****************************************
* Program napisal Damian Daszkiewicz *
* na potrzeby ksiazki *
* Edycja plikow binarnych *
* Nie roszcze zadnych praw *
* wobec tego porgramu, mozesz *
* robic z nim co Ci sie zywnie podoba *
****************************************
}

{Sorki za taki nieciekawy kod, ale w Pascalu juz dawno nie programowalem
a to moj pierwszy program napisany w FPC na potrzeby ksiazki po dlugiej
przerwie od Pascala}

Program Liczby;
uses crt;

Procedure Menu; forward;

procedure klawiszx;
var k:char;
Begin
k:=readkey;
if k=#0 then readkey;
end;

Procedure OProgramie;
Begin
clrscr;
textcolor(14);
writeln(' O programie');
textcolor(7);
writeln;
writeln('Ten program zostal napisany przez Damiana Daszkiewicza w FreePascalCompiler');
writeln('Program zostal napisany na potrzeby ksiazki "Edycja plikow binarnych" wydana');
writeln('przez wydawnictwo Helion.');
writeln('Program jest w pelni darmowy i nie zastrzegam do niego zadnych praw autorskich');
writeln;
writeln;
textcolor(14);
writeln(' Pomoc');
textcolor(7);
writeln('Program jest bardzo prosty w obsludze: najpierw wybieramy z jakiego systemu');
writeln('liczbowego chcemy konwertowac liczbe. Potem wpisujemy liczbe (mozna wpisac');
writeln('liczbe ujemna. Program automatycznie wyswieli liczbe zapisana w 3 pozostalych');
writeln('systemach liczbowych. Program jest bardzo prosty w obsludze. Wystepuje on');
writeln('wersji pod Linuxa jak i pod windowsa. Program akceptuje liczby max do');
writeln('65535 (jesli liczba ma byc ujemna to nie moze byc mniejsza niz -32736');
writeln('program zapisuje liczby w 1 lub 2 bajtach i podaje je w wersji dla procesora');
writeln('Intel tj. w liczbach 16 bitowych zamienia miejscami mlodszy ze starszym bajtem');
writeln;
end;

{Dodaj wiodace zera z przodu liczby binarnej}
Function Zera8(X:string;Znak:char):string;
var tmp:word;
P:string;
begin
p:='';
for tmp:=1 to 8-length(X) do P:=P+Znak;
Zera8:=p+X;
p:='';
end;

Function Zera16(X:string;Znak:char):string;
var tmp:word;
P:string;
begin
p:='';
for tmp:=1 to 16-length(X) do P:=P+Znak;
Zera16:=P+X;
p:='';
end;

Function Zera(X:string):string;
var tmp:word;
begin
tmp:=length(X);

if tmp=8 then Zera:=X;
if tmp=16 then Zera:=X;

if (tmp<8) then begin
Zera:=Zera8(X,'0');
end;

if (tmp<16>8) then begin
Zera:=Zera16(X,'0');
end;
end;


{dodaj jedynki z przodu liczby binarnej (do U2)}
Function DodajJedynki(X:string):string;
var tmp:word;
begin
tmp:=length(X);

if tmp=8 then DodajJedynki:=X;
if tmp=16 then DodajJedynki:=X;

if (tmp<8) then begin
DodajJedynki:=Zera8(X,'1');
end;

if (tmp<16>8) then begin
DodajJedynki:=Zera16(X,'1');
end;
end;


{10->2}
Function DecToBin(X:longint):string;
var
tmp:longint;
wynik:string;
reszta:byte;
resztas:string[1];
Begin
wynik:='';
tmp:=X;
repeat
reszta:=0;
resztas:='';
reszta:=tmp mod 2;
tmp:=tmp div 2;
str(reszta,resztas);
wynik:=resztas+wynik;
until tmp=0;


DecToBin:=wynik;
wynik:='';
reszta:=0;
tmp:=0;
X:=0;
end;

{Aby nie bawic sie w val'a}
Function DecToBinS(X:string):string;
var kod:word;
X2:word;
Begin
Val(x,x2,kod);
DecToBinS:=DecToBin(x2);
end;



{2->16}
Function Bin4Hex(X:string):string;
var W:string[1];
Begin
if X='0000' then W:='0';
if X='0001' then W:='1';
if X='0010' then W:='2';
if X='0011' then W:='3';
if X='0100' then W:='4';
if X='0101' then W:='5';
if X='0110' then W:='6';
if X='0111' then W:='7';
if X='1000' then W:='8';
if X='1001' then W:='9';
if X='1010' then W:='A';
if X='1011' then W:='B';
if X='1100' then W:='C';
if X='1101' then W:='D';
if X='1110' then W:='E';
if X='1111' then W:='F';
Bin4Hex:=W;
end;


Function BinToHex(X:string):string;
var
wynik:string;
Z:string[20];
Begin

Z:='';
if length(X)=8 then begin
Z:=X[1]+X[2]+X[3]+X[4];
wynik:=bin4hex(Z);
Z:=X[5]+X[6]+X[7]+X[8];
wynik:=wynik+bin4hex(Z);
end;

if length(X)=16 then begin
Z:=X[1]+X[2]+X[3]+X[4];
wynik:=bin4hex(Z);
Z:=X[5]+X[6]+X[7]+X[8];
wynik:=wynik+bin4hex(Z);
Z:=X[9]+X[10]+X[11]+X[12];
wynik:=wynik+bin4hex(Z);
Z:=X[13]+X[14]+X[15]+X[16];
wynik:=wynik+bin4hex(Z);
end;

BinToHex:=wynik;
end;


{16->2}
Function HB(X:string):string;
var W:string;
Begin
if X='0' then W:='0000';
if X='1' then W:='0001';
if X='2' then W:='0010';
if X='3' then W:='0011';
if X='4' then W:='0100';
if X='5' then W:='0101';
if X='6' then W:='0110';
if X='7' then W:='0111';
if X='8' then W:='1000';
if X='9' then W:='1001';
if X='A' then W:='1010';
if X='B' then W:='1011';
if X='C' then W:='1100';
if X='D' then W:='1101';
if X='E' then W:='1110';
if X='F' then W:='1111';

HB:=W;
end;


Function HexToBin(X:string):string;
var a:byte;
Wynik:string;
begin
wynik:='';
for a:=1 to length(X) do begin
Wynik:=Wynik+HB(X[a]);
end;
HexToBin:=Wynik;
end;

{8->2}
Function OB(X:string):string;
var W:string;
Begin
if X='0' then W:='000';
if X='1' then W:='001';
if X='2' then W:='010';
if X='3' then W:='011';
if X='4' then W:='100';
if X='5' then W:='101';
if X='6' then W:='110';
if X='7' then W:='111';

OB:=W;
end;


Function OctToBin(X:string):string;
var a:byte;
Wynik:string;
wynik2:string;
Czy:boolean;
begin
wynik:='';wynik2:='';czy:=false;
for a:=1 to length(X) do begin
Wynik:=Wynik+OB(X[a]);
end;

for a:=1 to length(wynik) do Begin
if wynik[a]='1' then czy:=true;
if czy=true then wynik2:=wynik2+wynik[a];
end;

OctToBin:=Wynik2;
end;


{2->10}
Function Potega2(A:word):word;
var w:word;
Begin
if a=0 then w:=1;
if a=1 then w:=2;
if a=2 then w:=4;
if a=3 then w:=8;
if a=4 then w:=16;
if a=5 then w:=32;
if a=6 then w:=64;
if a=7 then w:=128;
if a=8 then w:=256;
if a=9 then w:=512;
if a=10 then w:=1024;
if a=11 then w:=2048;
if a=12 then w:=4096;
if a=13 then w:=8192;
if a=14 then w:=16384;
if a=15 then w:=32768;
Potega2:=w;
end;


Function BinToDec(X:string):string;
var a:byte;
w:longint;
ws:string;
b:word;
begin
w:=0;
for a:=length(X) downto 1 do begin
b:=length(x)-a;
if X[a]='1' then w:=w+Potega2(b);
end;

str(w,ws);
BinToDec:=ws;
end;

{Czy w menu wybrano dobra opcje}
Function CzyDobry(X:string):boolean;
var Czy:Boolean;
begin
Czy:=False;
if X='1' then Czy:=True;
if X='2' then Czy:=True;
if X='3' then Czy:=True;
if X='4' then Czy:=True;
if X='5' then Czy:=True;
if X='6' then Czy:=True;
if X='7' then Czy:=True;
if X='0' then Czy:=True;
if (X='T') or (X='t') then Czy:=True;
if (X='Y') or (X='y') then Czy:=True;

CzyDobry:=Czy;
end;

Procedure Beep; {pisk z PCSpeakera}
begin
nosound;
sound(1300);
delay(200);
nosound;
end;

{Sprawdz czy liczba binarna jest poprawna (czy nie ma np. 11010AAAA) }
Function SprawdzPoprawnoscBin(X:string):boolean;
var a:word;
Pop:boolean;
Begin
pop:=true;
for a:=1 to length(x) do Begin
if (X[a]<0>>');
textcolor(14);
readln(Liczba);
textcolor(7);
cursoroff;
FormatBin:=SprawdzPoprawnoscBin(Liczba);
until FormatBin=True;
WprowadzLiczbeBinarna:=Liczba;
end;

Function WprowadzLiczbeBCD:string;
var FormatBin:boolean;
Liczba:string;
Begin
repeat
clrscr;
formatbin:=false;
writeln;
write('Wprowadz liczbe w kodzie BCD (ze spacjami lub bez) >>');
textcolor(14);
readln(Liczba);
textcolor(7);
FormatBin:=SprawdzPoprawnoscBCD(Liczba);
until FormatBin=True;
WprowadzLiczbeBCD:=Liczba;
end;


Function Bin4Oct(X:string):string;
var W:string;
Begin
if X='000' then W:='0';
if X='001' then W:='1';
if X='010' then W:='2';
if X='011' then W:='3';
if X='100' then W:='4';
if X='101' then W:='5';
if X='110' then W:='6';
if X='111' then W:='7';

Bin4Oct:=w;
end;


Function BinToOct(X:string):string;
var Z:string;
Tmp:string[3];
Wynik:string;
Y:string[1];
begin
Z:=Zera(X);
if length(Z)=8 then Begin
Z:='0'+Z;
wynik:='';
tmp:=Z[1]+Z[2]+Z[3];
Y:=Bin4Oct(tmp);
wynik:=wynik+Y;
tmp:=Z[4]+Z[5]+Z[6];
Y:=Bin4Oct(tmp);
wynik:=wynik+Y;
tmp:=Z[7]+Z[8]+Z[9];
Y:=Bin4Oct(tmp);
wynik:=wynik+y;
end;


if length(Z)=16 then Begin
Z:='00'+Z;
wynik:='';
tmp:=Z[1]+Z[2]+Z[3];
Y:=Bin4Oct(tmp);
if Y<0>>');
textcolor(14);
readln(Liczba);
textcolor(7);
cursoroff;
FormatBin:=SprawdzPoprawnoscHex(Liczba);
until FormatBin=True;
WprowadzLiczbeHex:=Liczba;
end;

Function SprawdzPoprawnoscDec(X:string):boolean;
var a:byte;
Pop:boolean;
Q:Real;
kod:word;
W:string[1];
Begin
pop:=true;
for a:=1 to length(x) do Begin
W:=X[a];
if (W<0>>');
textcolor(14);
readln(Liczba);
textcolor(7);
cursoroff;
FormatBin:=SprawdzPoprawnoscDec(Liczba);
until FormatBin=True;
WprowadzLiczbeDziesietna:=Liczba;
end;


Function SprawdzPoprawnoscOct(X:string):boolean;
var a:word;
Pop:boolean;
W:string[1];
Q:real;
kod:word;
Begin
pop:=true;w:='';q:=0;kod:=0;
for a:=1 to length(x) do Begin
W:=X[a];
if (W<0>>');
textcolor(14);
readln(Liczba);
textcolor(7);
cursoroff;
FormatBin:=SprawdzPoprawnoscOct(Liczba);
until FormatBin=True;
WprowadzLiczbeOsemkowa:=Liczba;
end;


{10->BCD}
Function DecToBCD(x:string):string;
var a:byte;
W:string;
C:char;
begin
W:='';
for a:=1 to length(X) do Begin
C:=X[a];
if C='0' then W:=W+'0000 ';
if C='1' then W:=W+'0001 ';
if C='2' then W:=W+'0010 ';
if C='3' then W:=W+'0011 ';
if C='4' then W:=W+'0100 ';
if C='5' then W:=W+'0101 ';
if C='6' then W:=W+'0110 ';
if C='7' then W:=W+'0111 ';
if C='8' then W:=W+'1000 ';
if C='9' then W:=W+'1001 ';
end;
DecToBCD:=W;
end;

Function BCDToDecQ(X:string):string;
Begin
if X='0000' then BCDToDecQ:='0';
if X='0001' then BCDToDecQ:='1';
if X='0010' then BCDToDecQ:='2';
if X='0011' then BCDToDecQ:='3';
if X='0100' then BCDToDecQ:='4';
if X='0101' then BCDToDecQ:='5';
if X='0110' then BCDToDecQ:='6';
if X='0111' then BCDToDecQ:='7';
if X='1000' then BCDToDecQ:='8';
if X='1001' then BCDToDecQ:='9';

if X='1010' then BCDToDecQ:='?';
if X='1011' then BCDToDecQ:='?';
if X='1100' then BCDToDecQ:='?';
if X='1101' then BCDToDecQ:='?';
if X='1110' then BCDToDecQ:='?';
if X='1111' then BCDToDecQ:='?';
end;


{BCD->10}
Function BCDtoDec(X:string):string;
var a:byte;
W:string;
Tm:string;
Tm2:string;
P:byte;
X1:real;
X2:byte;
Begin
P:=length(X);
tm:=''; tm2:='';
for a:=1 to P do Begin
if (X[a]<1>> -');
textcolor(14);
readln(Liczba);
textcolor(7);
cursoroff;
FormatBin:=SprawdzPoprawnoscDecUj(Liczba);
until FormatBin=True;
WprowadzLiczbeDziesietnaUjemna:=Liczba;
end;


{Negowanie liczby binarnej (do U2}
Function Neguj(X:string):string;
var a:byte;
Wynik:string;
Begin
wynik:='';
For a:=1 to length(X) do Begin
if X[a]='1' then Wynik:=Wynik+'0';
if X[a]='0' then Wynik:=Wynik+'1';
end;

Neguj:=Wynik;
end;

{Zamian kolejnosc (mlodszy ze starszym bajtem}
Function HexToIntelHex(X:string):string;
var Wynik:string;
Begin
if length(X)=1 then Begin
Wynik:='0'+X;
end;

if length(X)=2 then Wynik:=X;

if length(X)=3 then Begin
X:='0'+X;
Wynik:=X[3]+X[4]+' '+X[1]+X[2];
end;

if length(X)=4 then Wynik:=X[3]+X[4]+' '+X[1]+X[2];

HexToIntelHex:=Wynik;
end;


{Zamien kolejnosc (mlodszy ze starszym bajtem)}
Function BinToIntelBin(X:string):string;
var Wynik:string;
Tmp:string;
Begin
if Length(X)<8 then Begin
Wynik:=Zera8(X,'0');
end;

if length(X)=8 then Begin
Wynik:=X;
end;

if length(X)=16 then Begin
Wynik:=X[9]+X[10]+X[11]+X[12]+X[13]+X[14]+X[15]+X[16]+' ';
Wynik:=Wynik+X[1]+X[2]+X[3]+X[4]+X[5]+X[6]+X[7]+X[8];
end;

if (length(X)<16>8) then Begin
Tmp:=Zera16(X,'0');
X:=tmp;
Wynik:=X[9]+X[10]+X[11]+X[12]+X[13]+X[14]+X[15]+X[16]+' ';
Wynik:=Wynik+X[1]+X[2]+X[3]+X[4]+X[5]+X[6]+X[7]+X[8];
end;
BinToIntelBin:=Wynik;
end;

{Czy liczba BCD nie jest uszkodzona np. czy nie ma 1111}
Function BadBCD(X:string):boolean;
var a:byte;
W:boolean;
Begin
W:=false;

for a:=1 to length(X) do Begin
if X[a]='?' then W:=true;
end;

BadBCD:=w;
end;

{Tu jest glowna procedura ktora w zaleznosci od woli usera wybiera odpowiednie funckcje}
Procedure Wybieraj(X:char);
var Z:string;
Q:string;
Q2:string;
Q3:string;
Z2:longint;
kod:word;
i:byte;
T:string;
P:text;
begin
Z:=''; Q:=''; Q2:=''; Q3:=''; Z2:=0; kod:=0;

if X='0' then {halt(0)} exit;

if X='1' then Begin {bin->reszta}
Z:=WprowadzLiczbeBinarna;
Q:=BinToDec(Z);
writeln(Z,' w systemie dziesietnym ',Q);
Q:=DecToBCD(Q);
writeln(Z,' w kodzie BCD ',Q);
Q2:=BinToOct(Z);
writeln(Z,' w systemie osemkowym ',Q2);
writeln(Z,' w systemie szesnastkowym ',BinToHex(Zera(Z)),' (',HexToIntelHex(BinToHex(Zera(Z))),')');
end;

if X='2' then Begin {BCD->reszta}
Z:=WprowadzLiczbeBCD;
Q:='';
Q:=BCDToDec(Z);
if BadBCD(Q)=true then begin
writeln('Podana liczba nie jest liczba BCD');
beep;
end else Begin
Q2:=DecToBinS(Q);
writeln(Z,' w systemie binarnym ',Q2,' (',BinToIntelBin(Q2),')');
Q3:=BinToOct(Q2);
writeln(Z,' w systemie osemkowym ',Q3);
writeln(Z,' w systemie dziesietnym ',Q);
Q3:='';
Q3:=BinToHex(Zera(Q2));
writeln(Z,' w systemie szesnastkowym ',Q3,' (',HexToIntelHex(Q3),')');
end;
end;

if X='3' then Begin {dec->reszta}
Z:=WprowadzLiczbeDziesietna;
val(Z,Z2,kod);
Q:=DecToBin(Z2);
writeln(Z,' w systemie binarnym ',Q,' (',BinToIntelBin(Q),')');
writeln(Z,' w kodzie BCD ',DecToBcd(Z));
Q2:=Q;
Q2:=BinToOct(Q);
writeln(Z,' w systemie osemkowym ',Q2);
Q2:=BinToHex(Zera(Q));
writeln(Z,' w systemie szesnastkowym ',Q2,' (',HexToIntelHex(Q2),')');
end;

if X='4' then Begin {decUjemna->reszta}
Z:=WprowadzLiczbeDziesietnaUjemna;
{Konwersja na liczbe w U2}
Val(Z,Z2,kod);
if z2=0 then Begin
textcolor(4);
writeln('0 to nie jest liczba ujemna !!');
textcolor(7);
end else Begin
Q:=DecToBin(Z2);
Q:=Neguj(Q);
Q:=DodajJedynki(Q);
Q:=BinToDec(Q);
val(Q,Z2,kod);
Z2:=Z2+1;
str(Z2,Q);
Q:=DecToBin(Z2);
Z:='-'+Z;

{Normalny proces}
writeln(Z,' w systemie binarnym ',Q,' (',BinToIntelBin(Q),')');
Q2:=Q;
Q2:=BinToOct(Q);
writeln(Z,' w systemie osemkowym ',Q2);
Q2:=BinToHex(Zera(Q));
writeln(Z,' w systemie szesnastkowym ',Q2,' (',HexToIntelHex(Q2),')');
end;


end;

if X='5' then Begin {oct->reszta}
Z:=WprowadzLiczbeOsemkowa;
Q:=OctToBin(Z);
Q2:=BinToDec(Q);
writeln(Z,' w systemie binarnym ',Q,' (',BinToIntelBin(Q),')');
writeln(Z,' w kodzie BCD ',DecToBcd(Q2));
writeln(Z,' w systemie dziesietnym ',Q2);
writeln(Z,' w systemie szesnastkowym ',BinToHex(Zera(Q)),' (',HexToIntelHex(BinToHex(Zera(Q))),')');
end;

if X='6' then Begin {hex->reszta}
Z:=WprowadzLiczbeHex;
Q:=HexToBin(upcase(Z));
Q2:=BinToDec(Q);
writeln(Z,' w systemie binarnym ',Q,' (',BinToIntelBin(Q),')');
writeln(Z,' w kodzie BCD ',DecToBcd(Q2));
writeln(Z,' w systemie osemkowym ',BinToOct(Q));
writeln(Z,' w systemie dziesietnym ',Q2);
end;

if X='7' then Begin OProgramie end;


{ukryty tips}
if (X='T') or (X='t') then Begin
clrscr;
Assign(P,'tabela2.txt');
Rewrite(p);
for i:=0 to 255 do Begin
Z2:=i;
Q:=Zera(DecToBin(Z2));
T:=Q+#9;
str(i,Z);
T:=T+DecToBcd(Z)+#9;
Q2:=Q;
T:=T+BinToOct(Q)+#9;
str(i,q);
T:=T+Q+#9;
T:=T+BinToHex(Zera(Q2));
writeln(P,T);
end;
close(P);
textcolor(14);
writeln('Tabela zostala wyeksportowana do pliku tabela.txt');
textcolor(7);
end;

{ukryty tips}
if (X='Y') or (X='y') then Begin
clrscr;
Assign(P,'tabela2.txt');
Rewrite(p);
for i:=1 to 128 do Begin

{Konwersja na liczbe w U2}
Q:=DecToBin(i);
Q:=Neguj(Q);
Q:=DodajJedynki(Q);
Q:=BinToDec(Q);
val(Q,Z2,kod);
Z2:=Z2+1;
str(Z2,Q);
Q:=DecToBin(Z2);
Z2:=0;
T:=Q+#9;
Q2:=Q;

T:=T+BinToOct(Q)+#9;
str(i,q);
T:=T+'-'+Q+#9;
T:=T+BinToHex(Zera(Q2));
writeln(P,T);
end;
close(P);
textcolor(14);
writeln('Tabela zostala wyeksportowana do pliku tabela2.txt');
textcolor(7);
end;

Writeln;Write('Nacisnij dowolny klawisz aby wrocic do '); textcolor(14); write('menu');
klawiszx;
Menu;
end;


Procedure Menu;
var
klawisz2:char;
CzyDobryKlawisz:boolean;
Begin
clrscr;
nosound; {dalem to profilaktycznie, bo czasami w procedurze beep nosound nie dziala}
textcolor(15);
writeln('Systemy liczbowe v 1.0 (c) Damian Daszkiewicz');
writeln;
textcolor(14);
writeln('M E N U: ');
textcolor(9);write('1)');textcolor(7);writeln(' Konwersja liczby z systemu binarnego na pozostale systemy liczbowe');
textcolor(9);write('2)');textcolor(7);writeln(' Konwersja liczby z systemu BCD na pozostale systemy liczbowe');
textcolor(9);write('3)');textcolor(7);writeln(' Konwersja liczby z systemu dziesietnego na pozostale systemy liczbowe');
textcolor(9);write('4)');textcolor(7);writeln(' Konwersja ujemnej liczby z sys. dziesietnego na pozostale systemy liczbowe');
textcolor(9);write('5)');textcolor(7);writeln(' Konwersja liczby z systemu osemkowego na pozostale systemy liczbowe');
textcolor(9);write('6)');textcolor(7);writeln(' Konwersja liczby z systemu szesnastkowego na pozostale systemy liczbowe');
textcolor(9);write('7)');textcolor(7);writeln(' O programie & pomoc');
textcolor(9);write('0)');textcolor(7);writeln(' Wyjscie');

klawisz2:=readkey;
if klawisz2=#0 then klawisz2:=readkey;
CzyDobryKlawisz:=CzyDobry(klawisz2);

if CzyDobryKlawisz=false then begin
Beep;
menu;
end;

if CzyDobryKlawisz=true then Wybieraj(klawisz2);
klawisz2:=#0;
end;

Procedure Pozegnanie;
var i:integer;
Begin
clrscr;
textbackground(1); textcolor(14);
for i:=1 to 80 do write('=');
write(' Dziekuje za korzystanie z ksiazek wydawnictwa '); textcolor(15); write('Helion ');
for i:=1 to 80 do write('=');
textbackground(0); textcolor(7);
end;

Begin
cursoroff;
Menu;
Pozegnanie;
nosound; {profilaktyka}
cursoron;
end.

JSoftware
30-09-2007, 10:48 AM
This might be what you want. I have absolutely no idea what Brainer's code will do :P

function HexToExtended(value: string): extended;
var Values: packed array[0..9] of byte;
i: integer;
type PExtended = ^Extended;
begin
value := StringReplace(value, '$','', []);
while length(value) < 20 do
value := '0'+value;
for I := 0 to 9 do
Values[i] := strtoint('$'+copy(value, 20-i*2-1, 2));
result := PExtended(@values[0])^;
end;

function ExtendedToHex(value: Extended): string;
var Values: packed array[0..9] of byte absolute value;
i: integer;
begin
result := '$';
for I := 9 downto 0 do
result := result + IntToHex(Values[i], 2);
end;

Brainer
30-09-2007, 10:57 AM
I don't know either. Like I said, it's not my code. :) I just thought it could be useful. For all I know, it's hex->dec converter. :)

masonwheeler
30-09-2007, 06:24 PM
Thanks, JSoftware! I had to change the array index to compensate for little-endian storage, but your solution worked! :D


for I &#58;= 0 to 9 do
Values&#91;9 - i&#93; &#58;= strtoint&#40;'$'+copy&#40;value, 20-i*2-1, 2&#41;&#41;;

Mason