[fpc-pascal] binstr for single type
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.
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],' ');
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal