Decode Floating Point Value

From BeebWiki
Jump to: navigation, search


This program works with BASICS I-IV and decodes or encodes a Floating-Point variable between a Numeric Decimal value and the Internal BASIC representation.

   10 REM FLOATING POINT VARIABLE-DECIMAL
   20 Z=0
   30 PRINT''
   40 INPUT"1) VARIABLE TO DECIMAL"'"2) DECIMAL TO VARIABLE"';A$
   50 IF A$="2" INPUT''"Enter value ";Z
   60 IF A$="2" I%=3+?&4B4+256*?&4B5: PRINT'"Varable is:"'"Exponent  : ";~?I%'"Mantissa1 : ";~?(I%+1)'"Mantissa2 : ";~?(I%+2)'"Mantissa3 : ";~?(I%+3)'"Mantissa4 : ";~?(I%+4)'
   70 IF A$="1" INPUT''"Enter Exponent ";B$:B%=EVAL(B$)
   80 IF A$="1" INPUT"Enter Mantissa1 ";B$:C%=EVAL(B$)
   90 IF A$="1" INPUT"Enter Mantissa2 ";B$:D%=EVAL(B$)
  100 IF A$="1" INPUT"Enter Mantissa3 ";B$:E%=EVAL(B$)
  110 IF A$="1" INPUT"Enter Mantissa4 ";B$:F%=EVAL(B$)
  120 IF A$="1" I%=3+?&4B4+256*?&4B5:?I%=B%:?(I%+1)=C%:?(I%+2)=D%:?(I%+3)=E%:?(I%+4)=F%:PRINT'"The decimal is : ";Z
  130 RUN