Trick View: use fixed width for binary format

Closes #661
This commit is contained in:
Derek Bankieris 2018-08-21 11:49:21 -05:00 committed by dbankieris
parent 8c97db25f4
commit 3032aae3e4
4 changed files with 11 additions and 5 deletions

View File

@ -37,7 +37,8 @@ public class TVByte extends VSByte implements TrickViewFluent<TVByte.Format> {
Binary {
public String format(byte value, boolean unsigned) {
return Integer.toBinaryString(value & 0xFF);
String result = Integer.toBinaryString(value & 0xFF);
return "00000000".substring(result.length()) + result;
}
public byte parse(String value) {

View File

@ -32,12 +32,14 @@ public class TVInteger extends VSInteger implements TrickViewFluent<TVInteger.Fo
Decimal {
public String format(int value, boolean unsigned) {
String result;
if (unsigned && value < 0) {
return Long.toString(value + 4294967296L);
result = Long.toString(value + 4294967296L);
}
else {
return Integer.toString(value);
result = Integer.toString(value);
}
return "00000000000000000000000000000000".substring(result.length()) + result;
}
public int parse(String value) {

View File

@ -22,7 +22,9 @@ public class TVLong extends VSLong implements TrickViewFluent<TVLong.Format> {
Binary {
public String format(long value, boolean unsigned) {
return Long.toBinaryString(value);
String result = Long.toBinaryString(value);
return "0000000000000000000000000000000000000000000000000000000000000000"
.substring(result.length()) + result;
}
public long parse(String value) {

View File

@ -22,7 +22,8 @@ public class TVShort extends VSShort implements TrickViewFluent<TVShort.Format>
Binary {
public String format(short value, boolean unsigned) {
return Integer.toBinaryString(value & 0xFFFF);
String result = Integer.toBinaryString(value & 0xFFFF);
return "0000000000000000".substring(result.length()) + result;
}
public short parse(String value) {