// file: main_02_MENT.cpp // THIS IS C++, use clang++ #include #include "../helpers/println.hpp" struct PascalString{ int length; // number of chars used char characters[256]; // chars of some character string }; int hexDigitToInt(char hexDigit) { int value = 0; if(hexDigit > 47 && hexDigit < 58) value = hexDigit - 48; if(hexDigit > 96 && hexDigit < 103) value = hexDigit - 97 + 10; return value; } int hexStringToInt(PascalString binaryDigits) { int returnValue = 0; for(int i = 0; i <= binaryDigits.length; ++i) { returnValue += binaryDigits.characters[i]; } return returnValue; } void printPascalString(PascalString s) { for(int i = 0; i <= s.length; i++) { println(s.characters[i]); } } int main(int argc, char** argv, char** envp) { PascalString s = {3, '1', '0', '0'}; PascalString s2 = {4, 'f', 'f', 'f', 'f'}; println(hexStringToInt(s)); println(hexStringToInt(s2)); println(hexDigitToInt('d')); println(hexDigitToInt('9')); println(hexDigitToInt('2')); printPascalString(s2); return 0; }