(It would probably help to do Programming Project 4 before doing this one.) Write a program that converts numbers from base-2 notation to base-10 (ordinary decimal) notation. The program uses Swing to perform input and output via a window interface. The user enters a base-2 number in one text field and clicks a Convert button. The equivalent base-10 number then appears in another text field. Be sure that the two text fields are labeled. Include a Clear button that clears both text fields when clicked. Also, be sure that the close-window button works correctly. Hint: Include a private method that converts the string for a base-2 number to an equivalent int value.

Positional weighting is used to convert from binary to decimal; the binary string is processed one character at a time and the weight for that position added to a running total until all digits have been processed, so the final value is the decimal equivalent of the binary number. Just as with the conversion from decimal to binary in the previous Project, a slight complication arises from the order of the bits. The first binary digit is the most significant digit, so that weight must be determined first and the weight of each successive digit must be reduced by a factor of 2.


See the code in BinaryToDecimal.java. Uses WindowDestroyer.java.

Computer Science & Information Technology

You might also like to view...

Under the ________, employers who fail to warn employees of systems monitoring or allow employees access to electronic mail for personal reasons as well may lose some of their monitoring powers over employees due to an elevated expectation of privacy

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

It is illegal to create your own will in nearly all states in the U.S.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Which of the following commands can be used to back up files in case of system failure, supports long filenames, and can also back up device files?

A. diskdup B. bkup C. cpio D. sysbackup

Computer Science & Information Technology

Where can you change automatic or manual calculation mode in Excel?

A) Double CAL indicator on status bar B) Go to Tools >> Options >> Calculation and mark the corresponding radio button C) Both of above D) None of above

Computer Science & Information Technology