fixes bitvector conversion to hex number

This commit is contained in:
Eyck Jentzsch 2023-06-27 19:42:06 +02:00
parent c9a94334c4
commit aaf8a9e5d0
1 changed files with 7 additions and 4 deletions

View File

@ -149,25 +149,28 @@ public class BitVector implements IEvent {
int resWidth = (width - 1) / 4 + 1; int resWidth = (width - 1) / 4 + 1;
char[] value = getValue(); char[] value = getValue();
char[] res = new char[resWidth]; char[] res = new char[resWidth];
int start_idx = (value.length-1)%4;
for (int i = resWidth - 1; i >= 0; i--) { for (int i = resWidth - 1; i >= 0; i--) {
int digit = 0; int digit = 0;
for (int j = 3; j >= 0; j--) { for (int j = start_idx, jj=0; j >= 0; j--, jj++) {
if ((4 * i + j) < value.length) { if ((4 * i + j) < value.length) {
BitValue val = BitValue.fromChar(value[4 * i + j]); BitValue val = BitValue.fromChar(value[4 * i + jj]);
switch (val) { switch (val) {
case X: case X:
case Z: case Z:
res[i] = val.toChar(); res[i] = val.toChar();
continue; continue;
case ONE: case ONE:
digit += 1 << (3 - j); digit += 1 << j;
break; break;
default: default:
break; break;
} }
} }
} }
res[i] = Character.forDigit(digit, 16); // ((digit < 10) ? '0' + digit : 'a' + digit -10) if(res[i]==0)
res[i] = Character.forDigit(digit, 16); // ((digit < 10) ? '0' + digit : 'a' + digit -10)
start_idx=3;
} }
int idx=0; int idx=0;
while(res[idx]=='0' && idx<(res.length-1)) idx++; while(res[idx]=='0' && idx<(res.length-1)) idx++;