adds octal as number format, closes #322

This commit is contained in:
hneemann 2019-09-05 17:39:45 +02:00
parent 5e300079d1
commit 6b18c6b79d
3 changed files with 21 additions and 0 deletions

View File

@ -29,6 +29,10 @@ public enum IntFormat {
* binary * binary
*/ */
bin, bin,
/**
* octal
*/
oct,
/** /**
* ascii format * ascii format
*/ */
@ -73,6 +77,8 @@ public enum IntFormat {
return "0x" + toHex(inValue); return "0x" + toHex(inValue);
case bin: case bin:
return "0b" + toBin(inValue); return "0b" + toBin(inValue);
case oct:
return "0" + toOct(inValue);
case ascii: case ascii:
return "'" + (char) inValue.getValue() + "'"; return "'" + (char) inValue.getValue() + "'";
default: default:
@ -100,6 +106,19 @@ public enum IntFormat {
return sb.toString(); return sb.toString();
} }
private static String toOct(Value inValue) {
final int bits = inValue.getBits();
final int numChars = (bits - 1) / 3 + 1;
StringBuilder sb = new StringBuilder(numChars);
final long value = inValue.getValue();
for (int i = numChars - 1; i >= 0; i--) {
int c = (int) ((value >> (i * 3)) & 0x7);
sb.append(DIGITS[c]);
}
return sb.toString();
}
/** /**
* Creates a short hex representation of the given value. * Creates a short hex representation of the given value.

View File

@ -1117,6 +1117,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="key_intFormat_decSigned">Dezimal mit Vorzeichen</string> <string name="key_intFormat_decSigned">Dezimal mit Vorzeichen</string>
<string name="key_intFormat_def">Vorgabe</string> <string name="key_intFormat_def">Vorgabe</string>
<string name="key_intFormat_hex">Hexadezimal</string> <string name="key_intFormat_hex">Hexadezimal</string>
<string name="key_intFormat_oct">Oktal</string>
<string name="key_barrelSigned">Verschiebeweite hat Vorzeichen</string><!-- BarrelShifter --> <string name="key_barrelSigned">Verschiebeweite hat Vorzeichen</string><!-- BarrelShifter -->
<string name="key_barrelSigned_tt">Verschiebeweite verwendet Zweierkomplement</string> <string name="key_barrelSigned_tt">Verschiebeweite verwendet Zweierkomplement</string>
<string name="key_barrelShifterMode">Modus</string><!-- BarrelShifter --> <string name="key_barrelShifterMode">Modus</string><!-- BarrelShifter -->

View File

@ -1106,6 +1106,7 @@
<string name="key_intFormat_decSigned">signed decimal</string> <string name="key_intFormat_decSigned">signed decimal</string>
<string name="key_intFormat_def">default</string> <string name="key_intFormat_def">default</string>
<string name="key_intFormat_hex">hex</string> <string name="key_intFormat_hex">hex</string>
<string name="key_intFormat_oct">octal</string>
<string name="key_barrelSigned">shift input has sign</string><!-- BarrelShifter --> <string name="key_barrelSigned">shift input has sign</string><!-- BarrelShifter -->
<string name="key_barrelSigned_tt">shift input data has two complement format</string> <string name="key_barrelSigned_tt">shift input data has two complement format</string>
<string name="key_barrelShifterMode">Mode</string><!-- BarrelShifter --> <string name="key_barrelShifterMode">Mode</string><!-- BarrelShifter -->