Class Convert

java.lang.Object
  extended by Convert

public class Convert
extends java.lang.Object

Program for converting between decimal and binary


Constructor Summary
Convert()
           
 
Method Summary
static int binaryToDecimal(java.lang.String binary, boolean isSigned)
          Convert a binary string to a decimal integer
static java.lang.String binaryToHex(java.lang.String binary)
          Convert a binary string to a hexadecimal string
static java.lang.String decimalToBinary(int decimal, boolean isSigned, int width)
          Convert a decimal integer to a binary string
static java.lang.String decimalToHex(int decimal, boolean isSigned, int width)
          Convert a decimal integer to a hexadecimal string
static java.lang.String hexToBinary(java.lang.String hex)
          Convert a hexadecimal string to a binary string
static int hexToDecimal(java.lang.String hex, boolean isSigned)
          Convert a hexadecimal string to a decimal integer
static boolean isBinary(java.lang.String str)
          Checks if a number is a 16-bit (or less) binary string
static boolean isDecimal(java.lang.String str)
          Checks if a string contains a 16-bit (or fewer bits) decimal value
static boolean isHex(java.lang.String str)
          Checks if a string contains a 16-bit (or fewer bits) hexadecimal value
static void main(java.lang.String[] args)
          Main method for testing converter Repeatedly prompts user for conversion type and then performs conversion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Convert

public Convert()
Method Detail

isDecimal

public static boolean isDecimal(java.lang.String str)
Checks if a string contains a 16-bit (or fewer bits) decimal value

Parameters:
str - string to check
Returns:
true if string contains a decimal value, false otherwise

isHex

public static boolean isHex(java.lang.String str)
Checks if a string contains a 16-bit (or fewer bits) hexadecimal value

Parameters:
str - string to check
Returns:
true if string contains a hex value, false otherwise

isBinary

public static boolean isBinary(java.lang.String str)
Checks if a number is a 16-bit (or less) binary string

Parameters:
str - string to check
Returns:
true if string contains a binary value, false otherwise

decimalToBinary

public static java.lang.String decimalToBinary(int decimal,
                                               boolean isSigned,
                                               int width)
Convert a decimal integer to a binary string

Parameters:
decimal - decimal integer to convert
isSigned - flag indicating whether value is signed
width - width in bits of decimal
Returns:
string holding binary value

decimalToHex

public static java.lang.String decimalToHex(int decimal,
                                            boolean isSigned,
                                            int width)
Convert a decimal integer to a hexadecimal string

Parameters:
decimal - decimal integer to convert
isSigned - flag indicating whether value is signed
width - width in hexadecimal digits
Returns:
string holding hexadecimal value

binaryToDecimal

public static int binaryToDecimal(java.lang.String binary,
                                  boolean isSigned)
Convert a binary string to a decimal integer

Parameters:
binary - string holding binary value to convert
isSigned - flag indicating whether value is signed
Returns:
decimal integer

binaryToHex

public static java.lang.String binaryToHex(java.lang.String binary)
Convert a binary string to a hexadecimal string

Parameters:
binary - string holding binary value to convert
Returns:
string holding hexadecimal value

hexToDecimal

public static int hexToDecimal(java.lang.String hex,
                               boolean isSigned)
Convert a hexadecimal string to a decimal integer

Parameters:
hex - string holding hexadecimal value to convert
isSigned - flag indicating whether value is signed
Returns:
decimal integer

hexToBinary

public static java.lang.String hexToBinary(java.lang.String hex)
Convert a hexadecimal string to a binary string

Parameters:
hex - string holding hexadecimal value to convert
Returns:
string holding binary value

main

public static void main(java.lang.String[] args)
Main method for testing converter Repeatedly prompts user for conversion type and then performs conversion

Parameters:
args - command-line arguments (unused)