gosh dammit

This commit is contained in:
Johannes Theiner 2018-04-09 21:18:33 +02:00
parent a4255c3bb2
commit a3f4c78465
1 changed files with 83 additions and 80 deletions

View File

@ -56,16 +56,22 @@ PascalString intToDual(int n) {
char intToHexChar(int n) { char intToHexChar(int n) {
if (n > 9) { if (n > 9) {
switch (n) { switch (n) {
case 10: return 'A'; case 10:
case 11: return 'B'; return 'A';
case 12: return 'C'; case 11:
case 13: return 'D'; return 'B';
case 14: return 'E'; case 12:
case 15: return 'F'; return 'C';
default: return 'X'; case 13:
return 'D';
case 14:
return 'E';
case 15:
return 'F';
default:
return 'X';
} }
} } else return n + '0';
else return n + '0';
} }
PascalString intToHex(int n) { PascalString intToHex(int n) {
@ -81,13 +87,11 @@ PascalString intToHex(int n) {
} }
PascalString bitwiseDualAnd(PascalString a, PascalString b) { PascalString bitwiseDualAnd(PascalString a, PascalString b) {
PascalString shortString = a.length < b.length ? a : b; PascalString result = {a.length, '0'};
PascalString longString = a.length > b.length ? a : b;
PascalString result = {longString.length, '0'};
for(int i = longString.length; i >= 0; --i) { for (int i = b.length; i >= 0; --i) {
if(shortString.length < i) result.characters[i] = longString.characters[i]; if (a.length < i) result.characters[i] = a.characters[i];
result.characters[i] = longString.characters[i] & shortString.characters[i]; result.characters[i] = a.characters[i] & b.characters[i];
} }
return result; return result;
@ -98,7 +102,6 @@ PascalString bitwiseHexAnd(PascalString a, PascalString b) {
for (int i = b.length; i >= 0; --i) { for (int i = b.length; i >= 0; --i) {
if (a.length < i) result.characters[i] = a.characters[i]; if (a.length < i) result.characters[i] = a.characters[i];
println("i: ", i, " ", a.characters[i] & b.characters[i]);
result.characters[i] = a.characters[i] & b.characters[i]; result.characters[i] = a.characters[i] & b.characters[i];
} }