DecBin.BAS

This is a simple program that illustrates the power of BASIC for generating an interactive math program. This illustration could easily be written with three lines of code, but each step is placed on a seperate line to make explanation easier.

Its interactive because it receives information from the operator and displays processed information on the monitor.
Run the program in the usual manner, enter a decimal number and view the processed results.
Type Control C to stop the program and type SYSTEM (and ENTER) to return to Windows.



Lines 10 through 100 and 300 are remark statements that do nothing but document the program. Documentation is important to make the code readable for future editing.



Banner section
Line 110 sets the console display environment by turning off the keys and clearing the display.
Line 120 is the banner that initially announces the program's function.



Data Aquisition
Lines 150 through 170 serve as the input phaze.
The decimal number is INPUT into the numeric variable N
 The number is Absoluted to remove any minus sign and Integarized to remove any fractional component of N.
  The String variable B$ is cleared of any characters and will contain the binary results of the conversion process.



Processing
Line 200 through 240 process the decimal number in numeric variable N and builds the binary number in B$
Line 200 divides the number in N, with any fractional component into numeric variable K.
Line 210 does the same thing to itself, except that any fractional component is removed with the INT( ) function.

Line 220 serves a complex function using numeric values, string character values and logic.
  from the inside out; K is compared with N with the <> (not equal) logical function.
  If the two are indeed not equal a true (value of -1) is return. If they are equal, then a 0 is returned.
  The ABS ( ) function makes any minus return become positive.
  The STR$ ( ) function converts the numeric value into an alpha string character of 1 or zero into K$

Line 230 Modifies B$ by concantinating this character in K$ to the left hand side of itself.

Line 240 loops back on this same process at line 200 until the value in N becomes zero.
  When it finally services the least significan binary digit, it falls through to the next program steps.

Display
Line 270 simply prints out the contents of String variable B$.
Line 280 loops the program back to line 150 for another decimal number to be entered.

Program termination is accomplished by entering a control C from the keyboard to generate a program break.
Program control can be returned to Windows by typing in the command SYSTEM or by closing the BASIC console.



This entire module could easily be programmed using only three lines of code.
The Variable K and K$ could be removed entirely with a single, more comples program expression at the expense of removing the documentation that good house-keeping demands when writing a program.