Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions docs/api/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -73,51 +73,51 @@ 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

### 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
Expand All @@ -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
Expand Down
88 changes: 44 additions & 44 deletions docs/api/base/binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
// -----
Expand All @@ -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
// -----
Expand All @@ -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
// -----
Expand All @@ -114,93 +114,93 @@ 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

### 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

### 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
```
Expand All @@ -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"
```

Expand Down
Loading