[fpc-pascal] binstr for single type

Krekan krekan at netkosice.sk
Sat Nov 24 09:02:21 CET 2007

Hello, I need a routine binstr(var val:single;,....) since no such in the rtl exists I decided to write one. Also I wanted to make reverse routine bin2float where the input would be string containing 32 ones and zeroes. But I didn't want to bother with extracting mantissa, exponent, shifting adding dropped zero... One idea is to move entire singlenumber to the buffer (array of four bytes) and then I have values of 4 bytes allready figured so I can convert them to binary or in reverse convert 32 binary digits to  4 bytes and move them back to single. This approach worked until I used this on single numbers without floating part. But when I gave number with floating part it appended some numbers after my number.
Following code snippet demonstrates the idea.
If someone could point me what I am doing wrong there I would be gratefull.
program testsingle;
var number:single;
buf:array[1..4] of byte;
writeln('enter float number ');
writeln('you entered: ',number);
writeln('memory dump - byte by byte from left to right :');
for i:=1 to 4 do write(buf[i],' ');
writeln('result ');
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20071124/79ac7013/attachment.html>

More information about the fpc-pascal mailing list