diff --git a/src/main/java/org/harctoolbox/irp/IrpTransmogrifier.java b/src/main/java/org/harctoolbox/irp/IrpTransmogrifier.java index f8a956d4..1e67a08f 100644 --- a/src/main/java/org/harctoolbox/irp/IrpTransmogrifier.java +++ b/src/main/java/org/harctoolbox/irp/IrpTransmogrifier.java @@ -882,14 +882,10 @@ private void analyze(Analyzer analyzer, String[] names) throws NoDecoderMatchExc Protocol protocol = protocols.get(i); NameEngine definitions = protocol.getDefinitions(); for (Map.Entry definition : definitions) { - try { - String name = definition.getKey(); - int length = protocol.guessParameterLength(name); - long num = definition.getValue().toLong(); - out.print("\t" + IrCoreUtils.formatIntegerWithLeadingZeros(num, commandAnalyze.radix, length)); - } catch (NameUnassignedException ex) { - throw new ThisCannotHappenException(ex); - } + String name = definition.getKey(); + int length = protocol.guessParameterLength(name); + Number num = definition.getValue().toNumber(); + out.print("\t" + num.formatIntegerWithLeadingZeros(commandAnalyze.radix, length)); } out.println(); } diff --git a/src/main/java/org/harctoolbox/irp/Number.java b/src/main/java/org/harctoolbox/irp/Number.java index b340d58c..e91367e1 100644 --- a/src/main/java/org/harctoolbox/irp/Number.java +++ b/src/main/java/org/harctoolbox/irp/Number.java @@ -82,6 +82,14 @@ public static java.lang.Number parse(String str, int radix) { } } + private static String pad(String rawString, int length, double noBits) { + StringBuilder str = new StringBuilder(rawString); + int effectiveLength = (int) Math.ceil(length/noBits); + while (str.length() < effectiveLength) + str.insert(0, '0'); + return str.toString(); + } + private java.lang.Number data; public Number(java.lang.Number n) { @@ -201,4 +209,9 @@ public PrimaryItem leftHandSide() { public PrimaryItem substituteConstantVariables(Map constantVariables) { return this; } + + public String formatIntegerWithLeadingZeros(int radix, int length) { + return data instanceof Long ? IrCoreUtils.formatIntegerWithLeadingZeros(data.longValue(), radix, length) + : pad(((BigInteger) data).toString(radix), length, Math.log(radix)/Math.log(2.0)); + } }