Enhance Programing Project 11 in Chapter 13 that converts between binary and octal numbers by adding conversions to and from the hexadecimal number system and by using menus. A Convert menu should have four items, the first three of which are submenus. The first submenu—FromBinary—will have two menu items: “to octal” and “to hexadecimal.” The second submenu—FromOctal— will have two menu items, “to binary” and “to hexadecimal.” The third submenu— FromHexadecimal—will have two menu items, “to binary” and “to octal.” The final item in the Convert menu is “Clear.” Hexadecimal numbers use the digits 0 through 9 and the letters A through F. Note that each hexadecimal digit corresponds to a four-bit binary number, as follows:
Binary Hexadecimal
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
To convert a number from binary to hexadecimal, first group the bits in the binary number into sets of four and then apply the correspondences. For example, the binary number 0101110010100110 would be grouped as 0101 1100 1010 0110, which corresponds to the hexadecimal digits 5, C, A, and 6, respectively, Thus, the hexadecimal equivalent of the binary number is 5CA6. If the number of bits in the binary number is not divisible by 4, add 0’s at its beginning until it is. To convert an hexadecimal number to binary, we use our correspondence table in the reverse direction. For example, the hexadecimal number 7F6 is 0111 1111 0110, or 01111111 0110 in binary. Your application can omit the spaces we use to show the grouping of the bits.
To convert between octal and hexadecimal, first convert to binary.
This is an extension of the converter project in the previous chapter. Conceptually the changes required to add in hexadecimal numbers are easy, but there are some details that get in the way. Checking the validity of a hexadecimal number is complicated by the fact that the “digits” now include A through F. The groupings are for 4 bits instead of 3 bits, which increases the number of cases to consider. Even using an array to store the mappings is complicated by the alphabetic digits in a hexadecimal representation. One other factor to consider is how to convert between octal and hexadecimal. As directed, this code converts to binary first and then converts from binary to the desired base using existing methods. This makes those two conversions trivial.
See the code in BaseConverter.java.
You might also like to view...
The_______ is the current standard for hashing functions.
a) Secure Hash Algorithm. b) Safety Hash Algorithm. c) Signature Hash Algorithm. d) None of the above.
You use ____ to improve the performance of your programs.
A. icons B. multithreading C. interfaces D. object dictionaries
When looking for another word that means the same as "ruler," you could use the:
A) thesaurus. B) placeholder text. C) keywords box. D) Document Information Panel.
How does SSH port forwarding work?
What will be an ideal response?