@@ -8,14 +8,14 @@ namespace imeth {
88
99const std::string Base::DIGITS = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
1010
11- char Base::digitToChar (int digit) {
11+ char Base::digit_to_char (int digit) {
1212 if (digit < 0 || digit >= 36 ) {
1313 throw std::invalid_argument (" Digit out of range" );
1414 }
1515 return DIGITS[digit];
1616}
1717
18- int Base::charToDigit (char c) {
18+ int Base::char_to_digit (char c) {
1919 c = std::toupper (c);
2020 if (c >= ' 0' && c <= ' 9' ) {
2121 return c - ' 0' ;
@@ -27,7 +27,7 @@ int Base::charToDigit(char c) {
2727}
2828
2929// Convert decimal to any base
30- std::string Base::decimalToBase (int decimal, const int base) {
30+ std::string Base::decimal_to_base (int decimal, const int base) {
3131 if (base < 2 || base > 36 ) {
3232 throw std::invalid_argument (" Base must be between 2 and 36" );
3333 }
@@ -40,32 +40,32 @@ std::string Base::decimalToBase(int decimal, const int base) {
4040 std::string result = " " ;
4141 while (decimal > 0 ) {
4242 int remainder = decimal % base;
43- result = digitToChar (remainder) + result;
43+ result = digit_to_char (remainder) + result;
4444 decimal /= base;
4545 }
4646
4747 if (negative) result = " -" + result;
4848 return result;
4949}
5050
51- std::string Base::decimalToBinary (const int decimal) {
52- return decimalToBase (decimal, 2 );
51+ std::string Base::decimal_to_binary (const int decimal) {
52+ return decimal_to_base (decimal, 2 );
5353}
5454
55- std::string Base::decimalToTrinary (const int decimal) {
56- return decimalToBase (decimal, 3 );
55+ std::string Base::decimal_to_trinary (const int decimal) {
56+ return decimal_to_base (decimal, 3 );
5757}
5858
59- std::string Base::decimalToOctal (const int decimal) {
60- return decimalToBase (decimal, 8 );
59+ std::string Base::decimal_to_octal (const int decimal) {
60+ return decimal_to_base (decimal, 8 );
6161}
6262
63- std::string Base::decimalToHexadecimal (const int decimal) {
64- return decimalToBase (decimal, 16 );
63+ std::string Base::decimal_to_hexadecimal (const int decimal) {
64+ return decimal_to_base (decimal, 16 );
6565}
6666
6767// Convert from any base to decimal
68- int Base::baseToDecimal (const std::string& number, int base) {
68+ int Base::base_to_decimal (const std::string& number, int base) {
6969 if (base < 2 || base > 36 ) {
7070 throw std::invalid_argument (" Base must be between 2 and 36" );
7171 }
@@ -82,7 +82,7 @@ int Base::baseToDecimal(const std::string& number, int base) {
8282
8383 // Process from right to left
8484 for (int i = number.length () - 1 ; i >= static_cast <int >(start); --i) {
85- int digit = charToDigit (number[i]);
85+ int digit = char_to_digit (number[i]);
8686 if (digit >= base) {
8787 throw std::invalid_argument (" Invalid digit for base" );
8888 }
@@ -93,49 +93,49 @@ int Base::baseToDecimal(const std::string& number, int base) {
9393 return negative ? -result : result;
9494}
9595
96- int Base::binaryToDecimal (const std::string& binary) {
97- return baseToDecimal (binary, 2 );
96+ int Base::binary_to_decimal (const std::string& binary) {
97+ return base_to_decimal (binary, 2 );
9898}
9999
100- int Base::trinaryToDecimal (const std::string& trinary) {
101- return baseToDecimal (trinary, 3 );
100+ int Base::trinary_to_decimal (const std::string& trinary) {
101+ return base_to_decimal (trinary, 3 );
102102}
103103
104- int Base::octalToDecimal (const std::string& octal) {
105- return baseToDecimal (octal, 8 );
104+ int Base::octal_to_decimal (const std::string& octal) {
105+ return base_to_decimal (octal, 8 );
106106}
107107
108- int Base::hexadecimalToDecimal (const std::string& hex) {
109- return baseToDecimal (hex, 16 );
108+ int Base::hexadecimal_to_decimal (const std::string& hex) {
109+ return base_to_decimal (hex, 16 );
110110}
111111
112112// Direct conversion between bases
113113std::string Base::convert (const std::string& number, const int fromBase, const int toBase) {
114- const int decimal = baseToDecimal (number, fromBase);
115- return decimalToBase (decimal, toBase);
114+ const int decimal = base_to_decimal (number, fromBase);
115+ return decimal_to_base (decimal, toBase);
116116}
117117
118118// Arithmetic operations in different bases
119- std::string Base::addInBase (const std::string& num1, const std::string& num2, const int base) {
120- const int dec1 = baseToDecimal (num1, base);
121- const int dec2 = baseToDecimal (num2, base);
122- return decimalToBase (dec1 + dec2, base);
119+ std::string Base::add_in_base (const std::string& num1, const std::string& num2, const int base) {
120+ const int dec1 = base_to_decimal (num1, base);
121+ const int dec2 = base_to_decimal (num2, base);
122+ return decimal_to_base (dec1 + dec2, base);
123123}
124124
125- std::string Base::subtractInBase (const std::string& num1, const std::string& num2, const int base) {
126- const int dec1 = baseToDecimal (num1, base);
127- const int dec2 = baseToDecimal (num2, base);
128- return decimalToBase (dec1 - dec2, base);
125+ std::string Base::subtract_in_base (const std::string& num1, const std::string& num2, const int base) {
126+ const int dec1 = base_to_decimal (num1, base);
127+ const int dec2 = base_to_decimal (num2, base);
128+ return decimal_to_base (dec1 - dec2, base);
129129}
130130
131- std::string Base::multiplyInBase (const std::string& num1, const std::string& num2, const int base) {
132- const int dec1 = baseToDecimal (num1, base);
133- const int dec2 = baseToDecimal (num2, base);
134- return decimalToBase (dec1 * dec2, base);
131+ std::string Base::multiply_in_base (const std::string& num1, const std::string& num2, const int base) {
132+ const int dec1 = base_to_decimal (num1, base);
133+ const int dec2 = base_to_decimal (num2, base);
134+ return decimal_to_base (dec1 * dec2, base);
135135}
136136
137137// Utility functions
138- bool Base::isValidInBase (const std::string& number, const int base) {
138+ bool Base::is_valid_in_base (const std::string& number, const int base) {
139139 if (number.empty () || base < 2 || base > 36 ) {
140140 return false ;
141141 }
@@ -144,7 +144,7 @@ bool Base::isValidInBase(const std::string& number, const int base) {
144144
145145 for (size_t i = start; i < number.length (); ++i) {
146146 try {
147- int digit = charToDigit (number[i]);
147+ int digit = char_to_digit (number[i]);
148148 if (digit >= base) {
149149 return false ;
150150 }
@@ -156,7 +156,7 @@ bool Base::isValidInBase(const std::string& number, const int base) {
156156 return true ;
157157}
158158
159- std::string Base::toUpperCase (const std::string& str) {
159+ std::string Base::to_upper_case (const std::string& str) {
160160 std::string result = str;
161161 std::ranges::transform (result, result.begin (), ::toupper);
162162 return result;
0 commit comments