hey, eine andere Fehlermeldung
This commit is contained in:
parent
a3f4c78465
commit
37a116cf63
|
@ -5,29 +5,29 @@
|
||||||
|
|
||||||
#include "../helpers/println.hpp"
|
#include "../helpers/println.hpp"
|
||||||
|
|
||||||
struct PascalString {
|
struct PascalString{
|
||||||
int length; // number of chars used
|
int length; // number of chars used
|
||||||
char characters[256]; // chars of some character string
|
char characters[256]; // chars of some character string
|
||||||
};
|
};
|
||||||
|
|
||||||
char cStringArea[1024];
|
char cStringArea[1024];
|
||||||
|
|
||||||
int hexDigitToInt(char hexDigit) {
|
int hexDigitToInt(char hexDigit) {
|
||||||
int value = 0;
|
int value = 0;
|
||||||
|
|
||||||
if (hexDigit > 47 && hexDigit < 58)
|
if(hexDigit > 47 && hexDigit < 58)
|
||||||
value = hexDigit - 48;
|
value = hexDigit - 48;
|
||||||
|
|
||||||
if (hexDigit > 96 && hexDigit < 103)
|
if(hexDigit > 96 && hexDigit < 103)
|
||||||
value = hexDigit - 97 + 10;
|
value = hexDigit - 97 + 10;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hexStringToInt(PascalString binaryDigits) {
|
int hexStringToInt(PascalString binaryDigits) {
|
||||||
int returnValue = 0;
|
int returnValue = 0;
|
||||||
|
|
||||||
for (int i = 0; i <= binaryDigits.length; ++i) {
|
for(int i = 0; i <= binaryDigits.length; ++i) {
|
||||||
returnValue += binaryDigits.characters[i];
|
returnValue += binaryDigits.characters[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ int hexStringToInt(PascalString binaryDigits) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void printPascalString(PascalString s) {
|
void printPascalString(PascalString s) {
|
||||||
for (int i = 0; i <= s.length; i++) {
|
for(int i = 0; i <= s.length; i++) {
|
||||||
print(s.characters[i]);
|
print(s.characters[i]);
|
||||||
}
|
}
|
||||||
println("");
|
println("");
|
||||||
|
@ -45,7 +45,7 @@ PascalString intToDual(int n) {
|
||||||
|
|
||||||
int i = std::to_string(n).length() * 4;
|
int i = std::to_string(n).length() * 4;
|
||||||
PascalString string = {i};
|
PascalString string = {i};
|
||||||
while (n >= 1) {
|
while(n >= 1) {
|
||||||
string.characters[i] = (n % 2) + '0';
|
string.characters[i] = (n % 2) + '0';
|
||||||
n = n / 2;
|
n = n / 2;
|
||||||
i--;
|
i--;
|
||||||
|
@ -54,30 +54,24 @@ PascalString intToDual(int n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char intToHexChar(int n) {
|
char intToHexChar(int n) {
|
||||||
if (n > 9) {
|
if(n > 9) {
|
||||||
switch (n) {
|
switch(n) {
|
||||||
case 10:
|
case 10: return 'A';
|
||||||
return 'A';
|
case 11: return 'B';
|
||||||
case 11:
|
case 12: return 'C';
|
||||||
return 'B';
|
case 13: return 'D';
|
||||||
case 12:
|
case 14: return 'E';
|
||||||
return 'C';
|
case 15: return 'F';
|
||||||
case 13:
|
default: return 'X';
|
||||||
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) {
|
||||||
int i = std::to_string(n).length();
|
int i = std::to_string(n).length();
|
||||||
PascalString string = {i};
|
PascalString string = {i};
|
||||||
while (n >= 1) {
|
while(n >= 1) {
|
||||||
string.characters[i] = intToHexChar(n % 16);
|
string.characters[i] = intToHexChar(n % 16);
|
||||||
n = n / 16;
|
n = n / 16;
|
||||||
i--;
|
i--;
|
||||||
|
@ -89,8 +83,9 @@ PascalString intToHex(int n) {
|
||||||
PascalString bitwiseDualAnd(PascalString a, PascalString b) {
|
PascalString bitwiseDualAnd(PascalString a, PascalString b) {
|
||||||
PascalString result = {a.length, '0'};
|
PascalString result = {a.length, '0'};
|
||||||
|
|
||||||
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,8 +95,9 @@ PascalString bitwiseDualAnd(PascalString a, PascalString b) {
|
||||||
PascalString bitwiseHexAnd(PascalString a, PascalString b) {
|
PascalString bitwiseHexAnd(PascalString a, PascalString b) {
|
||||||
PascalString result = {a.length, '0'};
|
PascalString result = {a.length, '0'};
|
||||||
|
|
||||||
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,53 +109,53 @@ int to_c_string(PascalString s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void line() {
|
void line() {
|
||||||
println("===================================");
|
println("===================================");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp) {
|
int main(int argc, char** argv, char** envp) {
|
||||||
|
|
||||||
PascalString s = {3, '1', '0', '0'};
|
PascalString s = {3, '1', '0', '0'};
|
||||||
PascalString s2 = {4, 'f', 'f', 'f', 'f'};
|
PascalString s2 = {4, 'f', 'f', 'f', 'f'};
|
||||||
println(hexStringToInt(s));
|
println(hexStringToInt(s));
|
||||||
line();
|
line();
|
||||||
println(hexStringToInt(s2));
|
println(hexStringToInt(s2));
|
||||||
line();
|
line();
|
||||||
println(hexDigitToInt('d'));
|
println(hexDigitToInt('d'));
|
||||||
line();
|
line();
|
||||||
println(hexDigitToInt('9'));
|
println(hexDigitToInt('9'));
|
||||||
line();
|
line();
|
||||||
println(hexDigitToInt('2'));
|
println(hexDigitToInt('2'));
|
||||||
|
|
||||||
printPascalString(s2);
|
printPascalString(s2);
|
||||||
line();
|
line();
|
||||||
|
|
||||||
int controlRegister = 128;
|
int controlRegister = 128;
|
||||||
controlRegister |= 64 + 32;
|
controlRegister |= 64+32;
|
||||||
controlRegister ^= 16;
|
controlRegister ^=16;
|
||||||
controlRegister &= 128 + 64;
|
controlRegister &= 128+64;
|
||||||
controlRegister <<= 1;
|
controlRegister <<= 1;
|
||||||
|
|
||||||
println(controlRegister);
|
println(controlRegister);
|
||||||
line();
|
line();
|
||||||
println(intToHexChar(6));
|
println(intToHexChar(6));
|
||||||
line();
|
line();
|
||||||
println(intToHexChar(10));
|
println(intToHexChar(10));
|
||||||
line();
|
line();
|
||||||
printPascalString(intToDual(4106));
|
printPascalString(intToDual(4106));
|
||||||
line();
|
line();
|
||||||
printPascalString(intToHex(965));
|
printPascalString(intToHex(965));
|
||||||
line();
|
line();
|
||||||
printPascalString(intToHex(1956));
|
printPascalString(intToHex(1956));
|
||||||
|
|
||||||
line();
|
line();
|
||||||
printPascalString(bitwiseDualAnd({3, '1', '1', '0'}, {4, '1', '1', '1', '0'}));
|
printPascalString(bitwiseDualAnd({3, '1', '1', '0'}, {4, '1', '1', '1', '0'}));
|
||||||
line();
|
line();
|
||||||
printPascalString(bitwiseDualAnd({3, '1', '1', '1'}, {4, '1', '1', '1', '0'}));
|
printPascalString(bitwiseDualAnd({3, '1', '1', '1'}, {4, '1', '1', '1', '0'}));
|
||||||
line();
|
line();
|
||||||
printPascalString(bitwiseDualAnd({3, '1', '1', '0'}, {4, '1', '1', '1', '1'}));
|
printPascalString(bitwiseDualAnd({3, '1', '1', '0'}, {4, '1', '1', '1', '1'}));
|
||||||
line();
|
line();
|
||||||
printPascalString(bitwiseDualAnd({3, '0', '1', '0'}, {4, '1', '0', '1', '1'}));
|
printPascalString(bitwiseDualAnd({3, '0', '1', '0'}, {4, '1', '0', '1', '1'}));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue