Write an application with a GUI that will convert numbers from binary to octal. Binary numbers are composed of just the digits 0 and 1. Octal numbers use the digits 0, 1, 2, 3, 4, 5, 6, and 7. Note that each octal digit corresponds to a three-bit binary number, as follows:

000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7

To convert a number from binary to octal, first group the bits in the binary number into sets of three and then apply the equivalent octal numbers. For example, the binary number 001000101110 would be grouped as 001 000 101 110, which corresponds to the octal digits 1, 0, 5, and 6, respectively, Thus, the octal equivalent of the binary number is 1056. If the number of bits in the binary number is not divisible by 3, add zeros at its beginning until it is. For example, since the binary number 1011011100100 has 13 bits, we would add two zeros before it to get 001011011100100. We would then group its bits as 001 011 011 100 100 and get 13344 as its octal equivalent.

To convert an octal number to binary, we use our correspondence table in the reverse direction. For example, the octal number 716 is 111 001 110, or 111 001 110 in binary. Your application can omit the spaces we use to show the grouping of the bits.
You will need a text field for the user to enter a number and a label for the results. Provide three buttons: To Octal, To Binary, and Clear. If the user clicks the Clear button, clear any text in the text field and label. If the user clicks one of the two conversion buttons, check whether the number in the text field is in the correct format. If it is not, display the message Bad

Format in the results label. If the format is ok, compute the converted value and display that in the results label.

This application does a conversion between binary and octal. Unlike the binary to decimal conversion, this can be done without any mathematics. We just need to have a translation table between octal digits to strings of binary bits. One complication is that when we translate from binary, we want to have groups of 3 bits. If the length of the string of binary bits is not divisible by 3, we will add zeros to the front. A couple methods are used to verify that the input strings are valid. Methods were also created for the conversions.


See the code in BinaryOctalConverter.java.

Computer Science & Information Technology

You might also like to view...

When using a box layout, how is the orientation – horizontal or vertical box – specified?

What will be an ideal response?

Computer Science & Information Technology

What is the process for suppressing the printing of an individual object on a page?

What will be an ideal response?

Computer Science & Information Technology

In most current systems, ________ is the type of RAM used

A) DRAM B) SDRAM C) DDR2 D) DDR3

Computer Science & Information Technology

If the root was ____ before an insert, it is now high on the side in which the insert was made.

A. even balanced B. left high C. right high D. unbalanced

Computer Science & Information Technology