unc comp 110 fall 07.

Program 3: Binary to decimal converter


Due: Thursday Oct 11, 11:59pm EST

Motivation

Converting between binary and decimal is tedious by hand. Create a JavaScript program to convert a binary number into the corresponding decimal number. The binary value could be any number of bits.

User interface

Create an HTML form similar to program 1 and program 2. Include these form elements in the give order:

  1. An input field to enter the binary number
  2. A button that makes the calculates the conversion
  3. An input field that displays the number
  4. Add instructions to the web page that explain how the converter should be used.
Using the interface
  1. User enters a binary value
  2. User presses the button
  3. The program displays the result in the third field

Output

There are two parts to the output.

First, your program validates that the input is a valid binary value. The binary value is valid if it consists of "1" and "0" characters. If the binary value is invalid, the result should be:

Invalid binary number

Second, if the binary value is valid then your program returns the decimal value. The binary value can be any number of bits.

Objective

The objective of program 3 is to design a program using a loop and string (array of characters). It also gives practice with converting binary/decimal numbers.

The main work in this program (ie. most of the time spent) is to design the algorithm (procedure) to convert the binary to decimal number. It requires looping through the characters of a string and computing the decimal value.

Here is an outline of the program (validate input and convert binary value)
  1. Read the binary value
  2. Check if the binary number is valid.
  3. If the binary value is valid, convert the binary value into the decimal value.
  4. Display the result. Either, invalid input or the decimal value.

I suggest separating the process of validating and converting the binary value.

Tips


Testing

Use the following online testing application to test your program. The tester demonstrates more examples of valid and invalid binary values. Your program must work with the tester; this is how we will grade your program.

Program 3 tester
http://wwwp.cs.unc.edu/~dorianm/comp110/grader/program3/

Grading

We will grade your HTML and JavaScript programming based on the following.

Programming and Submission

Store your HTML file on your local disk until it's finished, then save it into your Onyen public_html directory using a secret 8-character name. Do not link your calculator page to other pages in that directory.

When your assignment is ready, you will submit your assignment through Blackboard.