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
|
||||
};
|
||||
|
||||
int hexDigitToInt(char hexDigit) {
|
||||
int value = -1;
|
||||
|
||||
if(hexDigit > 47 && hexDigit < 58)
|
||||
value = hexDigit - 48;
|
||||
|
||||
if(hexDigit > 96 && hexDigit < 103)
|
||||
value = hexDigit - 97 + 10;
|
||||
|
||||
return value;
|
||||
void printPascalString(PascalString string) {
|
||||
for(char c : string.characters)
|
||||
print(c);
|
||||
println("");
|
||||
}
|
||||
|
||||
int hexStringToInt(PascalString binaryDigits) {
|
||||
int returnValue = 0;
|
||||
int lengthOfInt(int i) {
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user