Introduction The Number Converter is a Java program designed to facilitate the conversion of numbers between different number systems, including decimal, binary, octal, and hexadecimal. It also supports the generation of 1's and 2's complement binary representations for both positive and negative numbers. This program serves as a useful tool for computer science students, programmers, and enthusiasts who frequently work with different number systems and need a convenient way to perform conversions accurately. With its simple and intuitive interface, users can input numbers in one number system and quickly obtain their equivalents in other number systems. Additionally, users can generate the complement representations of decimal numbers, which are commonly used in computer arithmetic and digital logic circuits. Features Number System Conversions • Convert decimal numbers to binary, octal, and hexadecimal. • Convert binary numbers to decimal, octal, and hexadecimal. • Convert octal numbers to decimal, binary, and hexadecimal. • Convert hexadecimal numbers to decimal, binary, and octal. Complement Representations • Generate the 1's complement binary representation of decimal numbers. • Generate the 2's complement binary representation of decimal numbers. User Interaction • Interactive command-line interface for inputting numbers and viewing conversion results. • Easy-to-use interface suitable for both beginners and experienced users. Overview The Number Converter Java program provides methods to convert numbers between different number systems including decimal, binary, octal, and hexadecimal. Additionally, it supports the conversion of positive and negative numbers, as well as the generation of 1's and 2's complement binary representations. Usage To use the program, compile the NumberConverter.java file and run the compiled program. The program will prompt the user to input numbers for conversion and display the results accordingly. Functions
- decimalToBinary(int decimal) : String • Converts a decimal number to binary. • Parameters: • decimal: The decimal number to convert. • Returns: Binary representation as a string.
- decimalToOctal(int decimal) : String • Converts a decimal number to octal. • Parameters: • decimal: The decimal number to convert. • Returns: Octal representation as a string.
- decimalToHexadecimal(int decimal) : String • Converts a decimal number to hexadecimal. • Parameters: • decimal: The decimal number to convert. • Returns: Hexadecimal representation as a string.
- binaryToDecimal(String binary) : int • Converts a binary number to decimal. • Parameters: • binary: The binary number to convert. • Returns: Decimal representation as an integer.
- binaryToOctal(String binary) : String • Converts a binary number to octal. • Parameters: • binary: The binary number to convert. • Returns: Octal representation as a string.
- binaryToHexadecimal(String binary) : String • Converts a binary number to hexadecimal. • Parameters: • binary: The binary number to convert. • Returns: Hexadecimal representation as a string.
- octalToDecimal(String octal) : int • Converts an octal number to decimal. • Parameters: • octal: The octal number to convert. • Returns: Decimal representation as an integer.
- octalToBinary(String octal) : String • Converts an octal number to binary. • Parameters: • octal: The octal number to convert. • Returns: Binary representation as a string.
- octalToHexadecimal(String octal) : String • Converts an octal number to hexadecimal. • Parameters: • octal: The octal number to convert. • Returns: Hexadecimal representation as a string.
- hexadecimalToDecimal(String hexadecimal) : int • Converts a hexadecimal number to decimal. • Parameters: • hexadecimal: The hexadecimal number to convert. • Returns: Decimal representation as an integer.
- hexadecimalToBinary(String hexadecimal) : String • Converts a hexadecimal number to binary. • Parameters: • hexadecimal: The hexadecimal number to convert. • Returns: Binary representation as a string.
- hexadecimalToOctal(String hexadecimal) : String • Converts a hexadecimal number to octal. • Parameters: • hexadecimal: The hexadecimal number to convert. • Returns: Octal representation as a string.
- decimalToOnesComplement(int decimal) : String • Generates the 1's complement binary representation of a decimal number. • Parameters: • decimal: The decimal number to convert. • Returns: 1's complement binary representation as a string.
- decimalToTwosComplement(int decimal) : String • Generates the 2's complement binary representation of a decimal number. • Parameters: • decimal: The decimal number to convert. • Returns: 2's complement binary representation as a string. Example Usage The main method in the program demonstrates the usage of each conversion function. Upon running the program, the user will be prompted to input numbers for various conversions, and the results will be displayed accordingly. Dependencies • This program is written in Java and does not require any external dependencies.