From 845195dab82ed95c65637331f52e6ee867c8c7ad Mon Sep 17 00:00:00 2001 From: lordpaijo Date: Tue, 25 Nov 2025 13:41:58 +0700 Subject: [PATCH 1/2] refactor(Base): Using for methods name in Base. --- include/imeth/base/base.hpp | 34 ++++++------- include/imeth/base/binary.hpp | 24 ++++----- include/imeth/base/hexadecimal.hpp | 16 +++--- include/imeth/base/octal.hpp | 8 +-- src/base/base.cpp | 78 +++++++++++++++--------------- src/base/binary.cpp | 68 +++++++++++++------------- src/base/hexadecimal.cpp | 38 +++++++-------- src/base/octal.cpp | 26 +++++----- 8 files changed, 146 insertions(+), 146 deletions(-) diff --git a/include/imeth/base/base.hpp b/include/imeth/base/base.hpp index 8a4e714..a31a22c 100644 --- a/include/imeth/base/base.hpp +++ b/include/imeth/base/base.hpp @@ -5,34 +5,34 @@ namespace imeth { class Base { public: // Convert FROM decimal TO any base (2-36) - static std::string decimalToBinary(int decimal); - static std::string decimalToTrinary(int decimal); - static std::string decimalToOctal(int decimal); - static std::string decimalToHexadecimal(int decimal); - static std::string decimalToBase(int decimal, int base); + static std::string decimal_to_binary(int decimal); + static std::string decimal_to_trinary(int decimal); + static std::string decimal_to_octal(int decimal); + static std::string decimal_to_hexadecimal(int decimal); + static std::string decimal_to_base(int decimal, int base); // Convert FROM any base TO decimal - static int binaryToDecimal(const std::string& binary); - static int trinaryToDecimal(const std::string& trinary); - static int octalToDecimal(const std::string& octal); - static int hexadecimalToDecimal(const std::string& hex); - static int baseToDecimal(const std::string& number, int base); + static int binary_to_decimal(const std::string& binary); + static int trinary_to_decimal(const std::string& trinary); + static int octal_to_decimal(const std::string& octal); + static int hexadecimal_to_decimal(const std::string& hex); + static int base_to_decimal(const std::string& number, int base); // Direct conversion between bases (goes through decimal) static std::string convert(const std::string& number, int fromBase, int toBase); // Arithmetic operations in different bases - static std::string addInBase(const std::string& num1, const std::string& num2, int base); - static std::string subtractInBase(const std::string& num1, const std::string& num2, int base); - static std::string multiplyInBase(const std::string& num1, const std::string& num2, int base); + static std::string add_in_base(const std::string& num1, const std::string& num2, int base); + static std::string subtract_in_base(const std::string& num1, const std::string& num2, int base); + static std::string multiply_in_base(const std::string& num1, const std::string& num2, int base); // Utility functions - static bool isValidInBase(const std::string& number, int base); - static std::string toUpperCase(const std::string& str); + static bool is_valid_in_base(const std::string& number, int base); + static std::string to_upper_case(const std::string& str); private: static const std::string DIGITS; - static char digitToChar(int digit); - static int charToDigit(char c); + static char digit_to_char(int digit); + static int char_to_digit(char c); }; } // namespace imeth diff --git a/include/imeth/base/binary.hpp b/include/imeth/base/binary.hpp index d452e40..0f30d96 100644 --- a/include/imeth/base/binary.hpp +++ b/include/imeth/base/binary.hpp @@ -4,8 +4,8 @@ namespace imeth { namespace Binary { // Conversion - std::string fromDecimal(int decimal); - int toDecimal(const std::string& binary); + std::string from_decimal(int decimal); + int to_decimal(const std::string& binary); // Arithmetic operations std::string add(const std::string& a, const std::string& b); @@ -13,17 +13,17 @@ namespace Binary { std::string multiply(const std::string& a, const std::string& b); // Bitwise operations - std::string bitwiseAND(const std::string& a, const std::string& b); - std::string bitwiseOR(const std::string& a, const std::string& b); - std::string bitwiseXOR(const std::string& a, const std::string& b); - std::string bitwiseNOT(const std::string& binary); - std::string leftShift(const std::string& binary, int positions); - std::string rightShift(const std::string& binary, int positions); + std::string bitwise_AND(const std::string& a, const std::string& b); + std::string bitwise_OR(const std::string& a, const std::string& b); + std::string bitwise_XOR(const std::string& a, const std::string& b); + std::string bitwise_NOT(const std::string& binary); + std::string left_shift(const std::string& binary, int positions); + std::string right_shift(const std::string& binary, int positions); // Utility - bool isValid(const std::string& binary); - std::string padLeft(const std::string& binary, size_t length); - int countOnes(const std::string& binary); - int countZeros(const std::string& binary); + bool is_valid(const std::string& binary); + std::string pad_left(const std::string& binary, size_t length); + int count_ones(const std::string& binary); + int count_zeros(const std::string& binary); }; // namespace binary } // namespace imeth diff --git a/include/imeth/base/hexadecimal.hpp b/include/imeth/base/hexadecimal.hpp index 158d86c..2ea4ed2 100644 --- a/include/imeth/base/hexadecimal.hpp +++ b/include/imeth/base/hexadecimal.hpp @@ -5,8 +5,8 @@ namespace imeth { class Hexadecimal { public: // Conversion - static std::string fromDecimal(int decimal); - static int toDecimal(const std::string& hex); + static std::string from_decimal(int decimal); + static int to_decimal(const std::string& hex); // Arithmetic operations static std::string add(const std::string& a, const std::string& b); @@ -14,13 +14,13 @@ class Hexadecimal { static std::string multiply(const std::string& a, const std::string& b); // Utility - static bool isValid(const std::string& hex); - static std::string toUpperCase(const std::string& hex); - static std::string toLowerCase(const std::string& hex); - static std::string padLeft(const std::string& hex, size_t length); + static bool is_valid(const std::string& hex); + static std::string to_upper_case(const std::string& hex); + static std::string to_lower_case(const std::string& hex); + static std::string pad_left(const std::string& hex, size_t length); private: - static int charToDigit(char c); - static char digitToChar(int digit); + static int char_to_digit(char c); + static char digit_to_char(int digit); }; } // namespace imeth diff --git a/include/imeth/base/octal.hpp b/include/imeth/base/octal.hpp index 5b81682..29e7152 100644 --- a/include/imeth/base/octal.hpp +++ b/include/imeth/base/octal.hpp @@ -4,8 +4,8 @@ namespace imeth { namespace Octal { // Conversion - static std::string fromDecimal(int decimal); - static int toDecimal(const std::string& octal); + static std::string from_decimal(int decimal); + static int to_decimal(const std::string& octal); // Arithmetic operations static std::string add(const std::string& a, const std::string& b); @@ -13,7 +13,7 @@ namespace Octal { static std::string multiply(const std::string& a, const std::string& b); // Utility - static bool isValid(const std::string& octal); - static std::string padLeft(const std::string& octal, size_t length); + static bool is_valid(const std::string& octal); + static std::string pad_left(const std::string& octal, size_t length); }; // namespace octal } // namespace imeth diff --git a/src/base/base.cpp b/src/base/base.cpp index 499a5fa..bb6f7cb 100644 --- a/src/base/base.cpp +++ b/src/base/base.cpp @@ -8,14 +8,14 @@ namespace imeth { const std::string Base::DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -char Base::digitToChar(int digit) { +char Base::digit_to_char(int digit) { if (digit < 0 || digit >= 36) { throw std::invalid_argument("Digit out of range"); } return DIGITS[digit]; } -int Base::charToDigit(char c) { +int Base::char_to_digit(char c) { c = std::toupper(c); if (c >= '0' && c <= '9') { return c - '0'; @@ -27,7 +27,7 @@ int Base::charToDigit(char c) { } // Convert decimal to any base -std::string Base::decimalToBase(int decimal, const int base) { +std::string Base::decimal_to_base(int decimal, const int base) { if (base < 2 || base > 36) { throw std::invalid_argument("Base must be between 2 and 36"); } @@ -40,7 +40,7 @@ std::string Base::decimalToBase(int decimal, const int base) { std::string result = ""; while (decimal > 0) { int remainder = decimal % base; - result = digitToChar(remainder) + result; + result = digit_to_char(remainder) + result; decimal /= base; } @@ -48,24 +48,24 @@ std::string Base::decimalToBase(int decimal, const int base) { return result; } -std::string Base::decimalToBinary(const int decimal) { - return decimalToBase(decimal, 2); +std::string Base::decimal_to_binary(const int decimal) { + return decimal_to_base(decimal, 2); } -std::string Base::decimalToTrinary(const int decimal) { - return decimalToBase(decimal, 3); +std::string Base::decimal_to_trinary(const int decimal) { + return decimal_to_base(decimal, 3); } -std::string Base::decimalToOctal(const int decimal) { - return decimalToBase(decimal, 8); +std::string Base::decimal_to_octal(const int decimal) { + return decimal_to_base(decimal, 8); } -std::string Base::decimalToHexadecimal(const int decimal) { - return decimalToBase(decimal, 16); +std::string Base::decimal_to_hexadecimal(const int decimal) { + return decimal_to_base(decimal, 16); } // Convert from any base to decimal -int Base::baseToDecimal(const std::string& number, int base) { +int Base::base_to_decimal(const std::string& number, int base) { if (base < 2 || base > 36) { throw std::invalid_argument("Base must be between 2 and 36"); } @@ -82,7 +82,7 @@ int Base::baseToDecimal(const std::string& number, int base) { // Process from right to left for (int i = number.length() - 1; i >= static_cast(start); --i) { - int digit = charToDigit(number[i]); + int digit = char_to_digit(number[i]); if (digit >= base) { throw std::invalid_argument("Invalid digit for base"); } @@ -93,49 +93,49 @@ int Base::baseToDecimal(const std::string& number, int base) { return negative ? -result : result; } -int Base::binaryToDecimal(const std::string& binary) { - return baseToDecimal(binary, 2); +int Base::binary_to_decimal(const std::string& binary) { + return base_to_decimal(binary, 2); } -int Base::trinaryToDecimal(const std::string& trinary) { - return baseToDecimal(trinary, 3); +int Base::trinary_to_decimal(const std::string& trinary) { + return base_to_decimal(trinary, 3); } -int Base::octalToDecimal(const std::string& octal) { - return baseToDecimal(octal, 8); +int Base::octal_to_decimal(const std::string& octal) { + return base_to_decimal(octal, 8); } -int Base::hexadecimalToDecimal(const std::string& hex) { - return baseToDecimal(hex, 16); +int Base::hexadecimal_to_decimal(const std::string& hex) { + return base_to_decimal(hex, 16); } // Direct conversion between bases std::string Base::convert(const std::string& number, const int fromBase, const int toBase) { - const int decimal = baseToDecimal(number, fromBase); - return decimalToBase(decimal, toBase); + const int decimal = base_to_decimal(number, fromBase); + return decimal_to_base(decimal, toBase); } // Arithmetic operations in different bases -std::string Base::addInBase(const std::string& num1, const std::string& num2, const int base) { - const int dec1 = baseToDecimal(num1, base); - const int dec2 = baseToDecimal(num2, base); - return decimalToBase(dec1 + dec2, base); +std::string Base::add_in_base(const std::string& num1, const std::string& num2, const int base) { + const int dec1 = base_to_decimal(num1, base); + const int dec2 = base_to_decimal(num2, base); + return decimal_to_base(dec1 + dec2, base); } -std::string Base::subtractInBase(const std::string& num1, const std::string& num2, const int base) { - const int dec1 = baseToDecimal(num1, base); - const int dec2 = baseToDecimal(num2, base); - return decimalToBase(dec1 - dec2, base); +std::string Base::subtract_in_base(const std::string& num1, const std::string& num2, const int base) { + const int dec1 = base_to_decimal(num1, base); + const int dec2 = base_to_decimal(num2, base); + return decimal_to_base(dec1 - dec2, base); } -std::string Base::multiplyInBase(const std::string& num1, const std::string& num2, const int base) { - const int dec1 = baseToDecimal(num1, base); - const int dec2 = baseToDecimal(num2, base); - return decimalToBase(dec1 * dec2, base); +std::string Base::multiply_in_base(const std::string& num1, const std::string& num2, const int base) { + const int dec1 = base_to_decimal(num1, base); + const int dec2 = base_to_decimal(num2, base); + return decimal_to_base(dec1 * dec2, base); } // Utility functions -bool Base::isValidInBase(const std::string& number, const int base) { +bool Base::is_valid_in_base(const std::string& number, const int base) { if (number.empty() || base < 2 || base > 36) { return false; } @@ -144,7 +144,7 @@ bool Base::isValidInBase(const std::string& number, const int base) { for (size_t i = start; i < number.length(); ++i) { try { - int digit = charToDigit(number[i]); + int digit = char_to_digit(number[i]); if (digit >= base) { return false; } @@ -156,7 +156,7 @@ bool Base::isValidInBase(const std::string& number, const int base) { return true; } -std::string Base::toUpperCase(const std::string& str) { +std::string Base::to_upper_case(const std::string& str) { std::string result = str; std::ranges::transform(result, result.begin(), ::toupper); return result; diff --git a/src/base/binary.cpp b/src/base/binary.cpp index 86d07a1..9b037d3 100644 --- a/src/base/binary.cpp +++ b/src/base/binary.cpp @@ -5,7 +5,7 @@ namespace imeth { // Conversion -std::string Binary::fromDecimal(int decimal) { +std::string Binary::from_decimal(int decimal) { if (decimal == 0) return "0"; const bool negative = decimal < 0; @@ -21,7 +21,7 @@ std::string Binary::fromDecimal(int decimal) { return result; } -int Binary::toDecimal(const std::string& binary) { +int Binary::to_decimal(const std::string& binary) { if (binary.empty()) { throw std::invalid_argument("Empty binary string"); } @@ -46,43 +46,43 @@ int Binary::toDecimal(const std::string& binary) { // Arithmetic operations std::string Binary::add(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 + dec2); + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 + dec2); } std::string Binary::subtract(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 - dec2); + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 - dec2); } std::string Binary::multiply(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 * dec2); + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 * dec2); } // Bitwise operations -std::string Binary::bitwiseAND(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 & dec2); +std::string Binary::bitwise_AND(const std::string& a, const std::string& b) { + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 & dec2); } -std::string Binary::bitwiseOR(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 | dec2); +std::string Binary::bitwise_OR(const std::string& a, const std::string& b) { + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 | dec2); } -std::string Binary::bitwiseXOR(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 ^ dec2); +std::string Binary::bitwise_XOR(const std::string& a, const std::string& b) { + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 ^ dec2); } -std::string Binary::bitwiseNOT(const std::string& binary) { +std::string Binary::bitwise_NOT(const std::string& binary) { // For simplicity, flip all bits in the string std::string result = binary; for (char& c : result) { @@ -92,18 +92,18 @@ std::string Binary::bitwiseNOT(const std::string& binary) { return result; } -std::string Binary::leftShift(const std::string& binary, int positions) { - const int decimal = toDecimal(binary); - return fromDecimal(decimal << positions); +std::string Binary::left_shift(const std::string& binary, int positions) { + const int decimal = to_decimal(binary); + return from_decimal(decimal << positions); } -std::string Binary::rightShift(const std::string& binary, int positions) { - int decimal = toDecimal(binary); - return fromDecimal(decimal >> positions); +std::string Binary::right_shift(const std::string& binary, int positions) { + int decimal = to_decimal(binary); + return from_decimal(decimal >> positions); } // Utility -bool Binary::isValid(const std::string& binary) { +bool Binary::is_valid(const std::string& binary) { if (binary.empty()) return false; size_t start = (binary[0] == '-') ? 1 : 0; @@ -115,12 +115,12 @@ bool Binary::isValid(const std::string& binary) { return true; } -std::string Binary::padLeft(const std::string& binary, size_t length) { +std::string Binary::pad_left(const std::string& binary, size_t length) { if (binary.length() >= length) return binary; return std::string(length - binary.length(), '0') + binary; } -int Binary::countOnes(const std::string& binary) { +int Binary::count_ones(const std::string& binary) { int count = 0; for (const char c : binary) { if (c == '1') count++; @@ -128,7 +128,7 @@ int Binary::countOnes(const std::string& binary) { return count; } -int Binary::countZeros(const std::string& binary) { +int Binary::count_zeros(const std::string& binary) { int count = 0; for (const char c : binary) { if (c == '0') count++; diff --git a/src/base/hexadecimal.cpp b/src/base/hexadecimal.cpp index 1f41cc2..e9c7239 100644 --- a/src/base/hexadecimal.cpp +++ b/src/base/hexadecimal.cpp @@ -7,7 +7,7 @@ namespace imeth { // Helper functions -int Hexadecimal::charToDigit(char c) { +int Hexadecimal::char_to_digit(char c) { c = std::toupper(c); if (c >= '0' && c <= '9') { return c - '0'; @@ -18,7 +18,7 @@ int Hexadecimal::charToDigit(char c) { throw std::invalid_argument("Invalid hexadecimal character"); } -char Hexadecimal::digitToChar(const int digit) { +char Hexadecimal::digit_to_char(const int digit) { if (digit < 0 || digit > 15) { throw std::invalid_argument("Digit out of range"); } @@ -29,7 +29,7 @@ char Hexadecimal::digitToChar(const int digit) { } // Conversion -std::string Hexadecimal::fromDecimal(int decimal) { +std::string Hexadecimal::from_decimal(int decimal) { if (decimal == 0) return "0"; bool negative = decimal < 0; @@ -37,7 +37,7 @@ std::string Hexadecimal::fromDecimal(int decimal) { std::string result = ""; while (decimal > 0) { - result = digitToChar(decimal % 16) + result; + result = digit_to_char(decimal % 16) + result; decimal /= 16; } @@ -45,7 +45,7 @@ std::string Hexadecimal::fromDecimal(int decimal) { return result; } -int Hexadecimal::toDecimal(const std::string& hex) { +int Hexadecimal::to_decimal(const std::string& hex) { if (hex.empty()) { throw std::invalid_argument("Empty hexadecimal string"); } @@ -57,7 +57,7 @@ int Hexadecimal::toDecimal(const std::string& hex) { int power = 1; for (int i = hex.length() - 1; i >= static_cast(start); --i) { - int digit = charToDigit(hex[i]); + int digit = char_to_digit(hex[i]); result += digit * power; power *= 16; } @@ -67,25 +67,25 @@ int Hexadecimal::toDecimal(const std::string& hex) { // Arithmetic operations std::string Hexadecimal::add(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 + dec2); + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 + dec2); } std::string Hexadecimal::subtract(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 - dec2); + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 - dec2); } std::string Hexadecimal::multiply(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 * dec2); + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 * dec2); } // Utility -bool Hexadecimal::isValid(const std::string& hex) { +bool Hexadecimal::is_valid(const std::string& hex) { if (hex.empty()) return false; size_t start = (hex[0] == '-') ? 1 : 0; @@ -98,19 +98,19 @@ bool Hexadecimal::isValid(const std::string& hex) { return true; } -std::string Hexadecimal::toUpperCase(const std::string& hex) { +std::string Hexadecimal::to_upper_case(const std::string& hex) { std::string result = hex; std::ranges::transform(result, result.begin(), ::toupper); return result; } -std::string Hexadecimal::toLowerCase(const std::string& hex) { +std::string Hexadecimal::to_lower_case(const std::string& hex) { std::string result = hex; std::ranges::transform(result, result.begin(), ::tolower); return result; } -std::string Hexadecimal::padLeft(const std::string& hex, size_t length) { +std::string Hexadecimal::pad_left(const std::string& hex, size_t length) { if (hex.length() >= length) return hex; return std::string(length - hex.length(), '0') + hex; } diff --git a/src/base/octal.cpp b/src/base/octal.cpp index 36203c5..4fe6acc 100644 --- a/src/base/octal.cpp +++ b/src/base/octal.cpp @@ -5,7 +5,7 @@ namespace imeth { // Conversion -std::string Octal::fromDecimal(int decimal) { +std::string Octal::from_decimal(int decimal) { if (decimal == 0) return "0"; bool negative = decimal < 0; @@ -21,7 +21,7 @@ std::string Octal::fromDecimal(int decimal) { return result; } -int Octal::toDecimal(const std::string& octal) { +int Octal::to_decimal(const std::string& octal) { if (octal.empty()) { throw std::invalid_argument("Empty octal string"); } @@ -46,25 +46,25 @@ int Octal::toDecimal(const std::string& octal) { // Arithmetic operations std::string Octal::add(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 + dec2); + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 + dec2); } std::string Octal::subtract(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 - dec2); + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 - dec2); } std::string Octal::multiply(const std::string& a, const std::string& b) { - const int dec1 = toDecimal(a); - const int dec2 = toDecimal(b); - return fromDecimal(dec1 * dec2); + const int dec1 = to_decimal(a); + const int dec2 = to_decimal(b); + return from_decimal(dec1 * dec2); } // Utility -bool Octal::isValid(const std::string& octal) { +bool Octal::is_valid(const std::string& octal) { if (octal.empty()) return false; size_t start = (octal[0] == '-') ? 1 : 0; @@ -76,7 +76,7 @@ bool Octal::isValid(const std::string& octal) { return true; } -std::string Octal::padLeft(const std::string& octal, size_t length) { +std::string Octal::pad_left(const std::string& octal, size_t length) { if (octal.length() >= length) return octal; return std::string(length - octal.length(), '0') + octal; } From 7a7510c549f74ac7e6edbe1ac748c343ca9f386f Mon Sep 17 00:00:00 2001 From: lordpaijo Date: Tue, 25 Nov 2025 14:14:03 +0700 Subject: [PATCH 2/2] docs(Base): Using for methods name. --- docs/api/base/base.md | 80 +++++++++++++-------------- docs/api/base/binary.md | 88 +++++++++++++++--------------- docs/api/base/hexadecimal.md | 102 +++++++++++++++++------------------ docs/api/base/octal.md | 52 +++++++++--------- 4 files changed, 161 insertions(+), 161 deletions(-) diff --git a/docs/api/base/base.md b/docs/api/base/base.md index a452274..b9da532 100644 --- a/docs/api/base/base.md +++ b/docs/api/base/base.md @@ -17,41 +17,41 @@ The `Base` class is a general-purpose base converter that works with any base fr ### FROM Decimal TO Other Bases ```c++ -static std::string decimalToBinary(int decimal); -static std::string decimalToTrinary(int decimal); -static std::string decimalToOctal(int decimal); -static std::string decimalToHexadecimal(int decimal); -static std::string decimalToBase(int decimal, int base); +static std::string decimal_to_binary(int decimal); +static std::string decimal_to_trinary(int decimal); +static std::string decimal_to_octal(int decimal); +static std::string decimal_to_hexadecimal(int decimal); +static std::string decimal_to_base(int decimal, int base); ``` **Examples:** ```c++ -Base::decimalToBinary(42); // "101010" -Base::decimalToTrinary(42); // "1120" -Base::decimalToOctal(42); // "52" -Base::decimalToHexadecimal(42); // "2A" -Base::decimalToBase(42, 5); // "132" (base 5) -Base::decimalToBase(100, 12); // "84" (base 12) +Base::decimal_to_binary(42); // "101010" +Base::decimal_to_trinary(42); // "1120" +Base::decimal_to_octal(42); // "52" +Base::decimal_to_hexadecimal(42); // "2A" +Base::decimal_to_base(42, 5); // "132" (base 5) +Base::decimal_to_base(100, 12); // "84" (base 12) ``` ### FROM Other Bases TO Decimal ```c++ -static int binaryToDecimal(const std::string& binary); -static int trinaryToDecimal(const std::string& trinary); -static int octalToDecimal(const std::string& octal); -static int hexadecimalToDecimal(const std::string& hex); -static int baseToDecimal(const std::string& number, int base); +static int binary_to_decimal(const std::string& binary); +static int trinary_to_decimal(const std::string& trinary); +static int octal-to_decimal(const std::string& octal); +static int hexadecimal_to_decimal(const std::string& hex); +static int base_to_decimal(const std::string& number, int base); ``` **Examples:** ```c++ -Base::binaryToDecimal("101010"); // 42 -Base::trinaryToDecimal("1120"); // 42 -Base::octalToDecimal("52"); // 42 -Base::hexadecimalToDecimal("2A"); // 42 -Base::baseToDecimal("132", 5); // 42 (from base 5) -Base::baseToDecimal("84", 12); // 100 (from base 12) +Base::binary_to_decimal("101010"); // 42 +Base::trinary_to_decimal("1120"); // 42 +Base::octal-to_decimal("52"); // 42 +Base::hexadecimal_to_decimal("2A"); // 42 +Base::base_to_decimal("132", 5); // 42 (from base 5) +Base::base_to_decimal("84", 12); // 100 (from base 12) ``` ## Direct Base-to-Base Conversion @@ -73,19 +73,19 @@ Base::convert("123", 5, 12); // "32" (base 5 to base 12) ## Arithmetic in Different Bases ```c++ -static std::string addInBase(const std::string& num1, const std::string& num2, int base); -static std::string subtractInBase(const std::string& num1, const std::string& num2, int base); -static std::string multiplyInBase(const std::string& num1, const std::string& num2, int base); +static std::string add_in_base(const std::string& num1, const std::string& num2, int base); +static std::string substract_in_base(const std::string& num1, const std::string& num2, int base); +static std::string multiply_in_base(const std::string& num1, const std::string& num2, int base); ``` Perform arithmetic operations directly in any base. **Examples:** ```c++ -Base::addInBase("1010", "1100", 2); // "10110" (binary addition) -Base::addInBase("12", "23", 5); // "40" (base 5 addition) -Base::multiplyInBase("12", "3", 8); // "36" (octal multiplication) -Base::subtractInBase("100", "11", 3); // "12" (trinary subtraction) +Base::add_in_base("1010", "1100", 2); // "10110" (binary addition) +Base::add_in_base("12", "23", 5); // "40" (base 5 addition) +Base::multiply_in_base("12", "3", 8); // "36" (octal multiplication) +Base::substract_in_base("100", "11", 3); // "12" (trinary subtraction) ``` ## Utility Functions @@ -93,31 +93,31 @@ Base::subtractInBase("100", "11", 3); // "12" (trinary subtraction) ### Validation ```c++ -static bool isValidInBase(const std::string& number, int base); +static bool is_valid_in_base(const std::string& number, int base); ``` Check if a string is a valid number in a given base. **Examples:** ```c++ -Base::isValidInBase("123", 3); // false (3 is not valid in base 3) -Base::isValidInBase("123", 5); // true -Base::isValidInBase("FF", 16); // true -Base::isValidInBase("GG", 16); // false (G is not valid in hex) +Base::is_valid_in_base("123", 3); // false (3 is not valid in base 3) +Base::is_valid_in_base("123", 5); // true +Base::is_valid_in_base("FF", 16); // true +Base::is_valid_in_base("GG", 16); // false (G is not valid in hex) ``` ### Case Conversion ```c++ -static std::string toUpperCase(const std::string& str); +static std::string to_upper_case(const std::string& str); ``` Convert a base string to uppercase (useful for bases > 10). **Examples:** ```c++ -Base::toUpperCase("2a"); // "2A" -Base::toUpperCase("abc"); // "ABC" +Base::to_upper_case("2a"); // "2A" +Base::to_upper_case("abc"); // "ABC" ``` ## Supported Bases @@ -142,14 +142,14 @@ std::string octal = Base::convert("FF", 16, 8); // "377" ### Custom Bases ```c++ // Working with unusual bases -std::string base7 = Base::decimalToBase(100, 7); // "202" -int decimal = Base::baseToDecimal("202", 7); // 100 +std::string base7 = Base::decimal_to_base(100, 7); // "202" +int decimal = Base::base_to_decimal("202", 7); // 100 ``` ### Base Arithmetic ```c++ // Do math without converting to decimal -std::string result = Base::addInBase("1234", "567", 8); // "2023" (in octal) +std::string result = Base::add_in_base("1234", "567", 8); // "2023" (in octal) ``` ## Notes diff --git a/docs/api/base/binary.md b/docs/api/base/binary.md index 2ed08f1..76418a5 100644 --- a/docs/api/base/binary.md +++ b/docs/api/base/binary.md @@ -17,30 +17,30 @@ Binary is the foundation of computer systems. Every number in a computer is stor ### FROM Decimal TO Binary ```c++ -static std::string fromDecimal(int decimal); +static std::string from_decimal(int decimal); ``` **Examples:** ```c++ -Binary::fromDecimal(10); // "1010" -Binary::fromDecimal(42); // "101010" -Binary::fromDecimal(255); // "11111111" -Binary::fromDecimal(0); // "0" -Binary::fromDecimal(-5); // "-101" +Binary::from_decimal(10); // "1010" +Binary::from_decimal(42); // "101010" +Binary::from_decimal(255); // "11111111" +Binary::from_decimal(0); // "0" +Binary::from_decimal(-5); // "-101" ``` ### FROM Binary TO Decimal ```c++ -static int toDecimal(const std::string& binary); +static int to_decimal(const std::string& binary); ``` **Examples:** ```c++ -Binary::toDecimal("1010"); // 10 -Binary::toDecimal("101010"); // 42 -Binary::toDecimal("11111111"); // 255 -Binary::toDecimal("-101"); // -5 +Binary::to_decimal("1010"); // 10 +Binary::to_decimal("101010"); // 42 +Binary::to_decimal("11111111"); // 255 +Binary::to_decimal("-101"); // -5 ``` ## Arithmetic Operations @@ -66,14 +66,14 @@ These operations work at the bit level and are fundamental to computer programmi ### AND Operation ```c++ -static std::string bitwiseAND(const std::string& a, const std::string& b); +static std::string bitwise_AND(const std::string& a, const std::string& b); ``` Returns 1 only when both bits are 1. **Examples:** ```c++ -Binary::bitwiseAND("1100", "1010"); // "1000" +Binary::bitwise_AND("1100", "1010"); // "1000" // 1100 // &1010 // ----- @@ -82,14 +82,14 @@ Binary::bitwiseAND("1100", "1010"); // "1000" ### OR Operation ```c++ -static std::string bitwiseOR(const std::string& a, const std::string& b); +static std::string bitwise_OR(const std::string& a, const std::string& b); ``` Returns 1 when at least one bit is 1. **Examples:** ```c++ -Binary::bitwiseOR("1100", "1010"); // "1110" +Binary::bitwise_OR("1100", "1010"); // "1110" // 1100 // |1010 // ----- @@ -98,14 +98,14 @@ Binary::bitwiseOR("1100", "1010"); // "1110" ### XOR Operation ```c++ -static std::string bitwiseXOR(const std::string& a, const std::string& b); +static std::string bitwise_XOR(const std::string& a, const std::string& b); ``` Returns 1 only when bits are different. **Examples:** ```c++ -Binary::bitwiseXOR("1100", "1010"); // "110" +Binary::bitwise_XOR("1100", "1010"); // "110" // 1100 // ^1010 // ----- @@ -114,30 +114,30 @@ Binary::bitwiseXOR("1100", "1010"); // "110" ### NOT Operation ```c++ -static std::string bitwiseNOT(const std::string& binary); +static std::string bitwise_NOT(const std::string& binary); ``` Flips all bits (0→1, 1→0). **Examples:** ```c++ -Binary::bitwiseNOT("1010"); // "0101" -Binary::bitwiseNOT("1111"); // "0000" +Binary::bitwise_NOT("1010"); // "0101" +Binary::bitwise_NOT("1111"); // "0000" ``` ### Bit Shifting ```c++ -static std::string leftShift(const std::string& binary, int positions); -static std::string rightShift(const std::string& binary, int positions); +static std::string left_shift(const std::string& binary, int positions); +static std::string right_shift(const std::string& binary, int positions); ``` Shift bits left or right. Left shift multiplies by 2, right shift divides by 2. **Examples:** ```c++ -Binary::leftShift("101", 2); // "10100" (5 << 2 = 20) -Binary::rightShift("1100", 2); // "11" (12 >> 2 = 3) +Binary::left_shift("101", 2); // "10100" (5 << 2 = 20) +Binary::right_shift("1100", 2); // "11" (12 >> 2 = 3) ``` ## Utility Functions @@ -145,48 +145,48 @@ Binary::rightShift("1100", 2); // "11" (12 >> 2 = 3) ### Validation ```c++ -static bool isValid(const std::string& binary); +static bool is_valid(const std::string& binary); ``` Check if a string contains only valid binary digits (0 and 1). **Examples:** ```c++ -Binary::isValid("1010"); // true -Binary::isValid("1012"); // false (contains '2') -Binary::isValid("abc"); // false +Binary::is_valid("1010"); // true +Binary::is_valid("1012"); // false (contains '2') +Binary::is_valid("abc"); // false ``` ### Padding ```c++ -static std::string padLeft(const std::string& binary, size_t length); +static std::string pad_left(const std::string& binary, size_t length); ``` Add zeros to the left to reach a specific length. **Examples:** ```c++ -Binary::padLeft("101", 8); // "00000101" -Binary::padLeft("1111", 8); // "00001111" -Binary::padLeft("10101010", 4);// "10101010" (already longer) +Binary::pad_left("101", 8); // "00000101" +Binary::pad_left("1111", 8); // "00001111" +Binary::pad_left("10101010", 4);// "10101010" (already longer) ``` ### Counting Bits ```c++ -static int countOnes(const std::string& binary); -static int countZeros(const std::string& binary); +static int count_ones(const std::string& binary); +static int count_zeros(const std::string& binary); ``` Count the number of 1s or 0s in a binary number. **Examples:** ```c++ -Binary::countOnes("1010"); // 2 -Binary::countZeros("1010"); // 2 -Binary::countOnes("1111"); // 4 -Binary::countZeros("0000"); // 4 +Binary::count_ones("1010"); // 2 +Binary::count_zeros("1010"); // 2 +Binary::count_ones("1111"); // 4 +Binary::count_zeros("0000"); // 4 ``` ## Real-World Examples @@ -194,13 +194,13 @@ Binary::countZeros("0000"); // 4 ### Converting Your Age to Binary ```c++ int age = 15; -std::string binaryAge = Binary::fromDecimal(age); // "1111" +std::string binaryAge = Binary::from_decimal(age); // "1111" std::cout << "I'm " << binaryAge << " years old in binary!\n"; ``` ### Checking if a Number is Even ```c++ -std::string num = Binary::fromDecimal(42); // "101010" +std::string num = Binary::from_decimal(42); // "101010" // If last bit is 0, the number is even bool isEven = (num.back() == '0'); // true ``` @@ -209,18 +209,18 @@ bool isEven = (num.back() == '0'); // true ```c++ std::string message = "1010"; std::string key = "1100"; -std::string encrypted = Binary::bitwiseXOR(message, key); // "0110" -std::string decrypted = Binary::bitwiseXOR(encrypted, key);// "1010" (back to original!) +std::string encrypted = Binary::bitwise_XOR(message, key); // "0110" +std::string decrypted = Binary::bitwise_XOR(encrypted, key);// "1010" (back to original!) ``` ### Creating Bit Masks ```c++ // Create a mask with 4 ones -std::string mask = Binary::fromDecimal(15); // "1111" +std::string mask = Binary::from_decimal(15); // "1111" // Use AND to extract bits std::string data = "10110101"; -std::string result = Binary::bitwiseAND(data, Binary::padLeft(mask, 8)); +std::string result = Binary::bitwise_AND(data, Binary::padLeft(mask, 8)); // Gets the last 4 bits: "0101" ``` diff --git a/docs/api/base/hexadecimal.md b/docs/api/base/hexadecimal.md index 52cd3f6..d7ba29e 100644 --- a/docs/api/base/hexadecimal.md +++ b/docs/api/base/hexadecimal.md @@ -17,35 +17,35 @@ Hexadecimal (hex) uses 16 digits: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=1 ### FROM Decimal TO Hexadecimal ```c++ -static std::string fromDecimal(int decimal); +static std::string from_decimal(int decimal); ``` **Examples:** ```c++ -Hexadecimal::fromDecimal(10); // "A" -Hexadecimal::fromDecimal(15); // "F" -Hexadecimal::fromDecimal(16); // "10" -Hexadecimal::fromDecimal(255); // "FF" -Hexadecimal::fromDecimal(42); // "2A" -Hexadecimal::fromDecimal(4096); // "1000" -Hexadecimal::fromDecimal(-10); // "-A" +Hexadecimal::from_decimal(10); // "A" +Hexadecimal::from_decimal(15); // "F" +Hexadecimal::from_decimal(16); // "10" +Hexadecimal::from_decimal(255); // "FF" +Hexadecimal::from_decimal(42); // "2A" +Hexadecimal::from_decimal(4096); // "1000" +Hexadecimal::from_decimal(-10); // "-A" ``` ### FROM Hexadecimal TO Decimal ```c++ -static int toDecimal(const std::string& hex); +static int to_decimal(const std::string& hex); ``` **Examples:** ```c++ -Hexadecimal::toDecimal("A"); // 10 -Hexadecimal::toDecimal("F"); // 15 -Hexadecimal::toDecimal("10"); // 16 -Hexadecimal::toDecimal("FF"); // 255 -Hexadecimal::toDecimal("2A"); // 42 -Hexadecimal::toDecimal("1000"); // 4096 -Hexadecimal::toDecimal("ff"); // 255 (case insensitive) +Hexadecimal::to_decimal("A"); // 10 +Hexadecimal::to_decimal("F"); // 15 +Hexadecimal::to_decimal("10"); // 16 +Hexadecimal::to_decimal("FF"); // 255 +Hexadecimal::to_decimal("2A"); // 42 +Hexadecimal::to_decimal("1000"); // 4096 +Hexadecimal::to_decimal("ff"); // 255 (case insensitive) ``` ## Arithmetic Operations @@ -71,50 +71,50 @@ Hexadecimal::multiply("10", "10"); // "100" (16 × 16 = 256) ### Validation ```c++ -static bool isValid(const std::string& hex); +static bool is_valid(const std::string& hex); ``` Check if a string contains only valid hexadecimal digits (0-9, A-F). **Examples:** ```c++ -Hexadecimal::isValid("1234"); // true -Hexadecimal::isValid("ABCDEF"); // true -Hexadecimal::isValid("FF00"); // true -Hexadecimal::isValid("GHI"); // false (G, H, I are not hex digits) -Hexadecimal::isValid("ff"); // true (case insensitive) +Hexadecimal::is_valid("1234"); // true +Hexadecimal::is_valid("ABCDEF"); // true +Hexadecimal::is_valid("FF00"); // true +Hexadecimal::is_valid("GHI"); // false (G, H, I are not hex digits) +Hexadecimal::is_valid("ff"); // true (case insensitive) ``` ### Case Conversion ```c++ -static std::string toUpperCase(const std::string& hex); -static std::string toLowerCase(const std::string& hex); +static std::string to_upper_case(const std::string& hex); +static std::string to_lower_case(const std::string& hex); ``` Convert hex strings between upper and lowercase. **Examples:** ```c++ -Hexadecimal::toUpperCase("2a"); // "2A" -Hexadecimal::toUpperCase("ff"); // "FF" -Hexadecimal::toLowerCase("2A"); // "2a" -Hexadecimal::toLowerCase("FF"); // "ff" +Hexadecimal::to_upper_case("2a"); // "2A" +Hexadecimal::to_upper_case("ff"); // "FF" +Hexadecimal::to_lower_case("2A"); // "2a" +Hexadecimal::to_lower_case("FF"); // "ff" ``` ### Padding ```c++ -static std::string padLeft(const std::string& hex, size_t length); +static std::string pad_left(const std::string& hex, size_t length); ``` Add zeros to the left to reach a specific length. **Examples:** ```c++ -Hexadecimal::padLeft("FF", 4); // "00FF" -Hexadecimal::padLeft("A", 2); // "0A" -Hexadecimal::padLeft("1234", 3); // "1234" (already longer) +Hexadecimal::pad_left("FF", 4); // "00FF" +Hexadecimal::pad_left("A", 2); // "0A" +Hexadecimal::pad_left("1234", 3); // "1234" (already longer) ``` ## Real-World Examples @@ -125,9 +125,9 @@ Colors on screens are often represented in hex! ```c++ // RGB color: Red=255, Green=128, Blue=64 -std::string red = Hexadecimal::fromDecimal(255); // "FF" -std::string green = Hexadecimal::fromDecimal(128); // "80" -std::string blue = Hexadecimal::fromDecimal(64); // "40" +std::string red = Hexadecimal::from_decimal(255); // "FF" +std::string green = Hexadecimal::from_decimal(128); // "80" +std::string blue = Hexadecimal::from_decimal(64); // "40" std::string color = red + green + blue; // "FF8040" std::cout << "Color code: #" << color << "\n"; // #FF8040 @@ -139,9 +139,9 @@ std::cout << "Color code: #" << color << "\n"; // #FF8040 // Parse color #A1B2C3 std::string hexColor = "A1B2C3"; -int red = Hexadecimal::toDecimal(hexColor.substr(0, 2)); // 161 -int green = Hexadecimal::toDecimal(hexColor.substr(2, 2)); // 178 -int blue = Hexadecimal::toDecimal(hexColor.substr(4, 2)); // 195 +int red = Hexadecimal::to_decimal(hexColor.substr(0, 2)); // 161 +int green = Hexadecimal::to_decimal(hexColor.substr(2, 2)); // 178 +int blue = Hexadecimal::to_decimal(hexColor.substr(4, 2)); // 195 std::cout << "RGB(" << red << ", " << green << ", " << blue << ")\n"; ``` @@ -153,7 +153,7 @@ Computer memory addresses are shown in hex: ```c++ // A typical memory address std::string address = "7FFF5C"; -int decimal = Hexadecimal::toDecimal(address); // 8388444 +int decimal = Hexadecimal::to_decimal(address); // 8388444 std::cout << "Memory location: 0x" << address << "\n"; ``` @@ -172,21 +172,21 @@ Hex: F A 5 // Each group: F, A, 5 // Result: FA5 in hex -int decimal = Binary::toDecimal("111110100101"); // 4005 -std::string hex = Hexadecimal::fromDecimal(decimal); // "FA5" +int decimal = Binary::to_decimal("111110100101"); // 4005 +std::string hex = Hexadecimal::from_decimal(decimal); // "FA5" ``` ### Common Hex Values ```c++ // Powers of 16 -Hexadecimal::fromDecimal(16); // "10" -Hexadecimal::fromDecimal(256); // "100" -Hexadecimal::fromDecimal(4096); // "1000" +Hexadecimal::from_decimal(16); // "10" +Hexadecimal::from_decimal(256); // "100" +Hexadecimal::from_decimal(4096); // "1000" // Max values -Hexadecimal::fromDecimal(255); // "FF" (max 8-bit value) -Hexadecimal::fromDecimal(65535); // "FFFF" (max 16-bit value) +Hexadecimal::from_decimal(255); // "FF" (max 8-bit value) +Hexadecimal::from_decimal(65535); // "FFFF" (max 16-bit value) ``` ## Understanding Hexadecimal @@ -214,7 +214,7 @@ Example: `2A` in hex = (2×16) + (10×1) = 32 + 10 = 42 in decimal ```c++ // Count from 0 to 20 in hex for (int i = 0; i <= 20; ++i) { - std::cout << i << " = " << Hexadecimal::fromDecimal(i) << " (hex)\n"; + std::cout << i << " = " << Hexadecimal::from_decimal(i) << " (hex)\n"; } // Output includes: // 10 = A (hex) @@ -253,8 +253,8 @@ Hexadecimal::add("2A", "1F"); // "49" ```c++ // All F's are special -Hexadecimal::toDecimal("F"); // 15 (max 4 bits) -Hexadecimal::toDecimal("FF"); // 255 (max 8 bits / 1 byte) -Hexadecimal::toDecimal("FFF"); // 4095 (max 12 bits) -Hexadecimal::toDecimal("FFFF"); // 65535 (max 16 bits / 2 bytes) +Hexadecimal::to_decimal("F"); // 15 (max 4 bits) +Hexadecimal::to_decimal("FF"); // 255 (max 8 bits / 1 byte) +Hexadecimal::to_decimal("FFF"); // 4095 (max 12 bits) +Hexadecimal::to_decimal("FFFF"); // 65535 (max 16 bits / 2 bytes) ``` diff --git a/docs/api/base/octal.md b/docs/api/base/octal.md index 7431465..f186a55 100644 --- a/docs/api/base/octal.md +++ b/docs/api/base/octal.md @@ -17,32 +17,32 @@ Octal uses digits 0-7. It's a convenient way to represent binary numbers because ### FROM Decimal TO Octal ```c++ -static std::string fromDecimal(int decimal); +static std::string from_decimal(int decimal); ``` **Examples:** ```c++ -Octal::fromDecimal(8); // "10" -Octal::fromDecimal(64); // "100" -Octal::fromDecimal(42); // "52" -Octal::fromDecimal(255); // "377" -Octal::fromDecimal(0); // "0" -Octal::fromDecimal(-10); // "-12" +Octal::from_decimal(8); // "10" +Octal::from_decimal(64); // "100" +Octal::from_decimal(42); // "52" +Octal::from_decimal(255); // "377" +Octal::from_decimal(0); // "0" +Octal::from_decimal(-10); // "-12" ``` ### FROM Octal TO Decimal ```c++ -static int toDecimal(const std::string& octal); +static int to_decimal(const std::string& octal); ``` **Examples:** ```c++ -Octal::toDecimal("10"); // 8 -Octal::toDecimal("100"); // 64 -Octal::toDecimal("52"); // 42 -Octal::toDecimal("377"); // 255 -Octal::toDecimal("-12"); // -10 +Octal::to_decimal("10"); // 8 +Octal::to_decimal("100"); // 64 +Octal::to_decimal("52"); // 42 +Octal::to_decimal("377"); // 255 +Octal::to_decimal("-12"); // -10 ``` ## Arithmetic Operations @@ -68,32 +68,32 @@ Octal::add("77", "1"); // "100" (63 + 1 = 64 in decimal) ### Validation ```c++ -static bool isValid(const std::string& octal); +static bool is_valid(const std::string& octal); ``` Check if a string contains only valid octal digits (0-7). **Examples:** ```c++ -Octal::isValid("1234567"); // true -Octal::isValid("123"); // true -Octal::isValid("789"); // false (8 and 9 are not octal digits) -Octal::isValid("abc"); // false +Octal::is_valid("1234567"); // true +Octal::is_valid("123"); // true +Octal::is_valid("789"); // false (8 and 9 are not octal digits) +Octal::is_valid("abc"); // false ``` ### Padding ```c++ -static std::string padLeft(const std::string& octal, size_t length); +static std::string pad_left(const std::string& octal, size_t length); ``` Add zeros to the left to reach a specific length. **Examples:** ```c++ -Octal::padLeft("12", 4); // "0012" -Octal::padLeft("777", 4); // "0777" -Octal::padLeft("1234", 3); // "1234" (already longer) +Octal::pad_left("12", 4); // "0012" +Octal::pad_left("777", 4); // "0777" +Octal::pad_left("1234", 3); // "1234" (already longer) ``` ## Real-World Examples @@ -109,7 +109,7 @@ File permissions in Unix/Linux are often shown in octal! // r-x = 101 (binary) = 5 (octal) - others can read and execute std::string permissions = "755"; -int decimal = Octal::toDecimal(permissions); // 493 +int decimal = Octal::to_decimal(permissions); // 493 std::cout << "Decimal value: " << decimal << "\n"; ``` @@ -128,8 +128,8 @@ Octal: 7 5 2 // Each group: 7, 5, 2 // Result: 752 in octal -int decimal = Binary::toDecimal("111101010"); // 490 -std::string octal = Octal::fromDecimal(decimal); // "752" +int decimal = Binary::to_decimal("111101010"); // 490 +std::string octal = Octal::from_decimal(decimal); // "752" ``` ### Counting in Octal @@ -137,7 +137,7 @@ std::string octal = Octal::fromDecimal(decimal); // "752" ```c++ // Octal counting: 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, ..., 17, 20 for (int i = 0; i <= 20; ++i) { - std::cout << i << " = " << Octal::fromDecimal(i) << " (octal)\n"; + std::cout << i << " = " << Octal::from_decimal(i) << " (octal)\n"; } // Output: // 0 = 0 (octal)