02 Testat
This commit is contained in:
parent
fe0462e39f
commit
7faef81469
|
@ -8,31 +8,52 @@ struct PascalString{
|
||||||
char characters[256]; // chars of some character string
|
char characters[256]; // chars of some character string
|
||||||
};
|
};
|
||||||
|
|
||||||
int hexDigitToInt(char hexDigit) {
|
void printPascalString(PascalString string) {
|
||||||
int value = -1;
|
for(char c : string.characters)
|
||||||
|
print(c);
|
||||||
if(hexDigit > 47 && hexDigit < 58)
|
println("");
|
||||||
value = hexDigit - 48;
|
|
||||||
|
|
||||||
if(hexDigit > 96 && hexDigit < 103)
|
|
||||||
value = hexDigit - 97 + 10;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int hexStringToInt(PascalString binaryDigits) {
|
int lengthOfInt(int i) {
|
||||||
int returnValue = 0;
|
if(i < 8) return 1;
|
||||||
|
return 1 + lengthOfInt(i / 8);
|
||||||
for(int i = 0; i < binaryDigits.length; i++) {
|
|
||||||
int x = hexDigitToInt(binaryDigits.characters[i]);
|
|
||||||
std::cout << "i = " << i << " x = " << x << std::endl;
|
|
||||||
returnValue += x;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
|
PascalString intToOctal(int value) {
|
||||||
|
int i = lengthOfInt(value) + 1;
|
||||||
|
PascalString result = {i};
|
||||||
|
while(i > 1) {
|
||||||
|
result.characters[i] = (value % 8) + '0';
|
||||||
|
value = value / 8;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PascalString bitwiseDualAnd(PascalString a, PascalString b) {
|
||||||
|
PascalString result = {a.length};
|
||||||
|
println(result.length);
|
||||||
|
for(int i = a.length; i >= 0; --i) {
|
||||||
|
int ac = a.characters[i] - '0';
|
||||||
|
int bc = b.characters[i] - '0';
|
||||||
|
result.characters[i] = (ac & bc) + '0';
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv, char** envp) {
|
int main(int argc, char** argv, char** envp) {
|
||||||
std::cout << hexStringToInt({3, '2', 'f', '1'}) << std::endl;
|
println("=============printPascalString===============");
|
||||||
|
printPascalString({3, '3', 'f', '1'});
|
||||||
|
printPascalString({5, 'H', 'a', 'l', 'l', 'o'});
|
||||||
|
println("=============intToOctal===============");
|
||||||
|
printPascalString(intToOctal(7));
|
||||||
|
printPascalString(intToOctal(565));
|
||||||
|
printPascalString(intToOctal(585858));
|
||||||
|
println("=============bitwiseDualAnd===============");
|
||||||
|
printPascalString(bitwiseDualAnd({2, '0', '1'}, {2, '1', '0'}));
|
||||||
|
printPascalString(bitwiseDualAnd({2, '1', '1'}, {2, '1', '1'}));
|
||||||
|
printPascalString(bitwiseDualAnd({7, '1', '0', '1', '0', '1', '0', '1'}, {7, '0', '0', '1', '1', '0', '0', '1'}));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue