mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 07:48:29 -04:00
adds octal as number format, closes #322
This commit is contained in:
parent
5e300079d1
commit
6b18c6b79d
@ -29,6 +29,10 @@ public enum IntFormat {
|
||||
* binary
|
||||
*/
|
||||
bin,
|
||||
/**
|
||||
* octal
|
||||
*/
|
||||
oct,
|
||||
/**
|
||||
* ascii format
|
||||
*/
|
||||
@ -73,6 +77,8 @@ public enum IntFormat {
|
||||
return "0x" + toHex(inValue);
|
||||
case bin:
|
||||
return "0b" + toBin(inValue);
|
||||
case oct:
|
||||
return "0" + toOct(inValue);
|
||||
case ascii:
|
||||
return "'" + (char) inValue.getValue() + "'";
|
||||
default:
|
||||
@ -100,6 +106,19 @@ public enum IntFormat {
|
||||
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.
|
||||
|
@ -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_def">Vorgabe</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_tt">Verschiebeweite verwendet Zweierkomplement</string>
|
||||
<string name="key_barrelShifterMode">Modus</string><!-- BarrelShifter -->
|
||||
|
@ -1106,6 +1106,7 @@
|
||||
<string name="key_intFormat_decSigned">signed decimal</string>
|
||||
<string name="key_intFormat_def">default</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_tt">shift input data has two complement format</string>
|
||||
<string name="key_barrelShifterMode">Mode</string><!-- BarrelShifter -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user