(H: 60) Write a web page that allows users to convert an
8-bit unsigned binary number to decimal. Your web page should look
something like:
binary: [ ]
[CONVERT]
decimal: [ ]
When the CONVERT button is clicked, your JavaScript function should be
called. This function should have the following features:
- If exactly 8 characters were not typed into the binary
input text object then your program should pop up a small
warning window and clear the binary and decimal inputs.
- If the input binary number does not contain only 0's and
1's then your program should pop up a small warning window and
clear the binary and decimal inputs.
- If the binary input is valid then you should convert the
8-bit binary number to decimal and place the result in the
decimal field. This conversion must use a for
loop.
- Hint: If b is the string that you extract
from the binary text window, then you can check the
length of b using b.length, and you can
access each character of b using b.charAt(k)
where k is a number such as 0,1,... Other functions
that you will probably find useful are: parseInt()
and Math.pow().
The following written problems are from "An Invitation to Computer Science":