diff --git a/02_MENT/main_02_MENT.cpp b/02_MENT/main_02_MENT.cpp index 7e56780..e249175 100644 --- a/02_MENT/main_02_MENT.cpp +++ b/02_MENT/main_02_MENT.cpp @@ -36,8 +36,9 @@ int hexStringToInt(PascalString binaryDigits) { void printPascalString(PascalString s) { for(int i = 0; i <= s.length; i++) { - println(s.characters[i]); + print(s.characters[i]); } + println(); } PascalString intToDual(int n) { @@ -93,25 +94,42 @@ PascalString bitwiseDualAnd(PascalString a, PascalString b) { } PascalString bitwiseHexAnd(PascalString a, PascalString b) { + PascalString shortString = a.length < b.length ? a : b; + PascalString longString = a.length > b.length ? a : b; + PascalString result = {longString.length, '0'}; + for(int i = longString.length; i >= 0; --i) { + if(shortString.length < i) result.characters[i] = longString.characters[i]; + result.characters[i] = longString.characters[i] & shortString.characters[i]; + } + + return result; } int to_c_string(PascalString s) { } +void line() { +println("==================================="); +} + int main(int argc, char** argv, char** envp) { PascalString s = {3, '1', '0', '0'}; PascalString s2 = {4, 'f', 'f', 'f', 'f'}; println(hexStringToInt(s)); + line(); println(hexStringToInt(s2)); - + line(); println(hexDigitToInt('d')); + line(); println(hexDigitToInt('9')); + line(); println(hexDigitToInt('2')); printPascalString(s2); + line(); int controlRegister = 128; controlRegister |= 64+32; @@ -120,15 +138,25 @@ int main(int argc, char** argv, char** envp) { controlRegister <<= 1; println(controlRegister); - + line(); println(intToHexChar(6)); + line(); println(intToHexChar(10)); - + line(); printPascalString(intToDual(4106)); + line(); printPascalString(intToHex(965)); + line(); printPascalString(intToHex(1956)); - + + line(); printPascalString(bitwiseDualAnd({3, '1', '1', '0'}, {4, '1', '1', '1', '0'})); + line(); + printPascalString(bitwiseDualAnd({3, '1', '1', '1'}, {4, '1', '1', '1', '0'})); + line(); + printPascalString(bitwiseDualAnd({3, '1', '1', '0'}, {4, '1', '1', '1', '1'})); + line(); + printPascalString(bitwiseDualAnd({3, '0', '1', '0'}, {4, '1', '0', '1', '1'})); return 0; }