12345678910111213141516171819202122232425262728293031323334353637 |
-
- /**
- * Write a description of class Conversion here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class DisplayMode
- {
- enum Mode {
- Binary,
- Octal,
- Decimal,
- Hexadecimal
- }
-
- String switchedValue = new String();
-
- public String switchDisplayMode(Mode mode, String displayValue) {
- switch (mode) {
- case Binary:
- switchedValue = Long.toBinaryString(Double.doubleToLongBits(Double.parseDouble(displayValue)));
- break;
- case Octal:
- switchedValue = Long.toOctalString(Double.doubleToLongBits(Double.parseDouble(displayValue)));
- break;
- case Decimal:
- switchedValue = displayValue;
- break;
- case Hexadecimal:
- switchedValue = Double.toHexString(Double.parseDouble(displayValue));
- break;
- }
- return switchedValue;
- }
- }
|