mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
Add reverse byte order formats to Trick View
Format added for shorts, ints, and longs. Closes #482
This commit is contained in:
parent
25cb478fd6
commit
87e59a9d17
@ -63,6 +63,52 @@ public class TVInteger extends VSInteger implements TrickViewFluent<TVInteger.Fo
|
||||
public int parse(String value) {
|
||||
return new BigInteger(value, 16).intValue();
|
||||
}
|
||||
},
|
||||
|
||||
BinaryReverseBytes {
|
||||
public String format(int value, boolean unsigned) {
|
||||
return Integer.toBinaryString(Integer.reverseBytes(value));
|
||||
}
|
||||
|
||||
public int parse(String value) {
|
||||
return Integer.reverseBytes(new BigInteger(value, 2).intValue());
|
||||
}
|
||||
},
|
||||
|
||||
DecimalReverseBytes {
|
||||
public String format(int value, boolean unsigned) {
|
||||
value = Integer.reverseBytes(value);
|
||||
if (unsigned && value < 0) {
|
||||
return Long.toString(value + 4294967296L);
|
||||
}
|
||||
else {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
}
|
||||
|
||||
public int parse(String value) {
|
||||
return Integer.reverseBytes(new BigInteger(value, 10).intValue());
|
||||
}
|
||||
},
|
||||
|
||||
OctalReverseBytes {
|
||||
public String format(int value, boolean unsigned) {
|
||||
return Integer.toOctalString(Integer.reverseBytes(value));
|
||||
}
|
||||
|
||||
public int parse(String value) {
|
||||
return Integer.reverseBytes(new BigInteger(value, 8).intValue());
|
||||
}
|
||||
},
|
||||
|
||||
HexadecimalReverseBytes {
|
||||
public String format(int value, boolean unsigned) {
|
||||
return Integer.toHexString(Integer.reverseBytes(value));
|
||||
}
|
||||
|
||||
public int parse(String value) {
|
||||
return Integer.reverseBytes(new BigInteger(value, 16).intValue());
|
||||
}
|
||||
};
|
||||
|
||||
public abstract String format(int value, boolean unsigned);
|
||||
|
@ -64,6 +64,53 @@ public class TVLong extends VSLong implements TrickViewFluent<TVLong.Format> {
|
||||
public long parse(String value) {
|
||||
return new BigInteger(value, 16).longValue();
|
||||
}
|
||||
},
|
||||
|
||||
BinaryReverseBytes {
|
||||
public String format(long value, boolean unsigned) {
|
||||
return Long.toBinaryString(Long.reverseBytes(value));
|
||||
}
|
||||
|
||||
public long parse(String value) {
|
||||
return Long.reverseBytes(new BigInteger(value, 2).longValue());
|
||||
}
|
||||
},
|
||||
|
||||
DecimalReverseBytes {
|
||||
public String format(long value, boolean unsigned) {
|
||||
value = Long.reverseBytes(value);
|
||||
if (unsigned && value < 0) {
|
||||
return new BigInteger(Long.toString(value)).add(
|
||||
new BigInteger("18446744073709551616")).toString();
|
||||
}
|
||||
else {
|
||||
return Long.toString(value);
|
||||
}
|
||||
}
|
||||
|
||||
public long parse(String value) {
|
||||
return Long.reverseBytes(new BigInteger(value, 10).longValue());
|
||||
}
|
||||
},
|
||||
|
||||
OctalReverseBytes {
|
||||
public String format(long value, boolean unsigned) {
|
||||
return Long.toOctalString(Long.reverseBytes(value));
|
||||
}
|
||||
|
||||
public long parse(String value) {
|
||||
return Long.reverseBytes(new BigInteger(value, 8).longValue());
|
||||
}
|
||||
},
|
||||
|
||||
HexadecimalReverseBytes {
|
||||
public String format(long value, boolean unsigned) {
|
||||
return Long.toHexString(Long.reverseBytes(value));
|
||||
}
|
||||
|
||||
public long parse(String value) {
|
||||
return Long.reverseBytes(new BigInteger(value, 16).longValue());
|
||||
}
|
||||
};
|
||||
|
||||
public abstract String format(long value, boolean unsigned);
|
||||
|
@ -63,6 +63,52 @@ public class TVShort extends VSShort implements TrickViewFluent<TVShort.Format>
|
||||
public short parse(String value) {
|
||||
return new BigInteger(value, 16).shortValue();
|
||||
}
|
||||
},
|
||||
|
||||
BinaryReverseBytes {
|
||||
public String format(short value, boolean unsigned) {
|
||||
return Integer.toBinaryString(Short.reverseBytes(value) & 0xFFFF);
|
||||
}
|
||||
|
||||
public short parse(String value) {
|
||||
return Short.reverseBytes(new BigInteger(value, 2).shortValue());
|
||||
}
|
||||
},
|
||||
|
||||
DecimalReverseBytes {
|
||||
public String format(short value, boolean unsigned) {
|
||||
value = Short.reverseBytes(value);
|
||||
if (unsigned && value < 0) {
|
||||
return Integer.toString(value + 65536);
|
||||
}
|
||||
else {
|
||||
return Short.toString(value);
|
||||
}
|
||||
}
|
||||
|
||||
public short parse(String value) {
|
||||
return Short.reverseBytes(new BigInteger(value, 10).shortValue());
|
||||
}
|
||||
},
|
||||
|
||||
OctalReverseBytes {
|
||||
public String format(short value, boolean unsigned) {
|
||||
return Integer.toOctalString(Short.reverseBytes(value) & 0xFFFF);
|
||||
}
|
||||
|
||||
public short parse(String value) {
|
||||
return Short.reverseBytes(new BigInteger(value, 8).shortValue());
|
||||
}
|
||||
},
|
||||
|
||||
HexadecimalReverseBytes {
|
||||
public String format(short value, boolean unsigned) {
|
||||
return Integer.toHexString(Short.reverseBytes(value) & 0xFFFF);
|
||||
}
|
||||
|
||||
public short parse(String value) {
|
||||
return Short.reverseBytes(new BigInteger(value, 16).shortValue());
|
||||
}
|
||||
};
|
||||
|
||||
public abstract String format(short value, boolean unsigned);
|
||||
|
Loading…
Reference in New Issue
Block a user