Repository: TheAlgorithms/Python
Pull request: Create ipv4_conversion.py
### Describe your change:

Closes #9718
Closes #11013

* [x] Add an algorithm?
* [ ] Fix a bug or typo in an existing algorithm?
* [x] Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
* [ ] Documentation change?

### Checklist:
* [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md).
* [x] This pull request is all my own work -- I have not plagiarized.
* [x] I know that pull requests will not be merged if they fail the automated tests.
* [x] This PR only changes one algorithm file.  To ease review, please open separate PRs for separate algorithms.
* [x] All new Python files are placed inside an existing directory.
* [x] All filenames are in all lowercase characters with no spaces or dashes.
* [x] All functions and variable names follow Python naming conventions.
* [x] All function parameters and return values are annotated with Python [type hints](https://docs.python.org/3/library/typing.html).
* [x] All functions have [doctests](https://docs.python.org/3/library/doctest.html) that pass the automated testing.
* [x] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
* [ ] If this pull request resolves one or more open issues then the description above includes the issue number(s) with a [closing keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue): "Fixes #ISSUE-NUMBER".


Problem statement:
Speedup our eight slowest pytests (one at a time please)
### Feature description

At the end of our GitHub Actions `build` jobs, there is a list of the slowest ones.

Are there ways to speed up these tests without reducing our functionality or our code coverage?

Please only fix one algorithm per pull request.
* [ ] 16.64s call     neural_network/simple_neural_network.py::neural_network.simple_neural_network.forward_propagation
* [x] 6.15s call     backtracking/word_search.py::backtracking.word_search.word_exists
* [x] 4.61s call     digital_image_processing/test_digital_image_processing.py::test_local_binary_pattern
* [x] 2.59s call     backtracking/power_sum.py::backtracking.power_sum.backtrack
* [x] 2.19s call     machine_learning/xgboost_regressor.py::machine_learning.xgboost_regressor.main
* [x] 1.73s call     maths/prime_numbers.py::maths.prime_numbers.slow_primes
* [x] 1.43s call     backtracking/power_sum.py::backtracking.power_sum.solve
* [x] 1.00s call     other/dijkstra_bankers_algorithm.py::other.dijkstra_bankers_algorithm.BankersAlgorithm.main
================= 1506 passed, 25 warnings in 71.23s (0:01:11) =================

Also, those **25 pytest warnings** are worth fixing!!!

Hints from issue discussion:
I pointed out in #8785 that `neural_network/simple_neural_network.py` has multiple issues (I don't think it even implements a neural network) and could do with a rewrite. Ideally whatever new implementation replaces it should run a lot more quickly.
I checked the maths/prime_numbers.py file. In this file, there are three methods for finding prime numbers using different techniques. The simplest method, referred to as slow_prime (which uses a loop to iterate from 2 to n and print prime numbers), is taking a lot of time. Do we need it there? Since the other two methods are faster with just minor modifications for finding prime numbers, do we still need the slow_prime method in there?
Can `slow_prime()` be tested with smaller numbers?  We do not want to get rid of it but we want its test to finish faster.
https://github.com/TheAlgorithms/Python/blob/87494f1fa1022368d154477bdc035fd01f9e4382/maths/prime_numbers.py#L20-L21
Let's lower the `10_000` to `1_000`
If 'slow_prime()' is tested on small test cases, then the other two methods will also be tested on small test cases to compare the time taken among them.
If I reduce the test cases, do I need to raise a PR to check whether they finished faster, or is there any other method I can use to verify if the issue is resolved before submitting a PR?
When things are run on CI platforms like GitHub Actions then an environment variable `CI` is defined.
* https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

Can you use https://docs.python.org/3/library/os.html#os.getenv to see if `CI` is defined?  If `CI` is defined then set the number to 1_000 for all three tests and it if is not defined then set it to 10_000 for all three.
Okay, thanks. Let me try.
But if it is not defined, setting the test case to 10_000 will take the same amount of time as before, doesn't it?
Yes, but we do not care because it no longer slows down our build process.

I sped it up in #9851.

Commit message: [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Patch to review:
diff --git a/conversions/ipconversion.py b/conversions/ipconversion.py
new file mode 100644
index 000000000000..f59cbc5f9079
--- /dev/null
+++ b/conversions/ipconversion.py
@@ -0,0 +1,62 @@
+# https://www.geeksforgeeks.org/convert-ip-address-to-integer-and-vice-versa/
+
+
+def ip_to_decimal(ip_address: str) -> int:
+    """
+    Convert an IPv4 address to its decimal representation.
+
+    Args:
+        ip_address (str): A string representing an IPv4 address (e.g., "192.168.0.1").
+
+    Returns:
+        int: The decimal representation of the IP address.
+
+    >>> ip_to_decimal("192.168.0.1")
+    3232235521
+    >>> ip_to_decimal("10.0.0.255")
+    167772415
+    """
+
+    ip_parts = ip_address.split(".")
+    if len(ip_parts) != 4:
+        raise ValueError("Invalid IPv4 address format")
+
+    decimal_ip = 0
+    for part in ip_parts:
+        decimal_ip = (decimal_ip << 8) + int(part)
+
+    return decimal_ip
+
+
+def decimal_to_ip(decimal_ip: int) -> str:
+    """
+    Convert a decimal representation of an IP address to its IPv4 format.
+
+    Args:
+        decimal_ip (int): An integer representing the decimal IP address.
+
+    Returns:
+        str: The IPv4 representation of the decimal IP address.
+
+    >>> decimal_to_ip(3232235521)
+    '192.168.0.1'
+    >>> decimal_to_ip(167772415)
+    '10.0.0.255'
+    """
+
+    if not (0 <= decimal_ip <= 4294967295):
+        raise ValueError("Invalid decimal IP address")
+
+    ip_parts = []
+    for _ in range(4):
+        ip_parts.append(str(decimal_ip & 255))
+        decimal_ip >>= 8
+
+    ip_parts.reverse()
+    return ".".join(ip_parts)
+
+
+if __name__ == "__main__":
+    import doctest
+
+    doctest.testmod()


Code review comments:
diff_hunk: @@ -0,0 +1,62 @@
+# https://www.geeksforgeeks.org/convert-ip-address-to-integer-and-vice-versa/
+
+
+def ip_to_decimal(ip_address: str) -> int:
+    """
+    Convert an IPv4 address to its decimal representation.
+
+    Args:
+        ip_address (str): A string representing an IPv4 address (e.g., "192.168.0.1").
+
+    Returns:
+        int: The decimal representation of the IP address.
+
+    >>> ip_to_decimal("192.168.0.1")
+    3232235521
+    >>> ip_to_decimal("10.0.0.255")
+    167772415
+    """
+
+    ip_parts = ip_address.split(".")
path: conversions/ipconversion.py
text: @user1:
See: https://github.com/TheAlgorithms/Python/blob/master/maths/is_ip_v4_address_valid.py
```suggestion
    octets = ip_address.split(".")
```

@author:
Using more Appropriate variable names indeed make the code easy to understand Thanks!.

diff_hunk: @@ -0,0 +1,62 @@
+# https://www.geeksforgeeks.org/convert-ip-address-to-integer-and-vice-versa/
+
+
+def ip_to_decimal(ip_address: str) -> int:
+    """
+    Convert an IPv4 address to its decimal representation.
+
+    Args:
+        ip_address (str): A string representing an IPv4 address (e.g., "192.168.0.1").
+
+    Returns:
+        int: The decimal representation of the IP address.
+
+    >>> ip_to_decimal("192.168.0.1")
+    3232235521
+    >>> ip_to_decimal("10.0.0.255")
+    167772415
+    """
+
+    ip_parts = ip_address.split(".")
+    if len(ip_parts) != 4:
+        raise ValueError("Invalid IPv4 address format")
+
+    decimal_ip = 0
+    for part in ip_parts:
+        decimal_ip = (decimal_ip << 8) + int(part)
+
+    return decimal_ip
+
+
+def decimal_to_ip(decimal_ip: int) -> str:
+    """
+    Convert a decimal representation of an IP address to its IPv4 format.
+
+    Args:
+        decimal_ip (int): An integer representing the decimal IP address.
+
+    Returns:
+        str: The IPv4 representation of the decimal IP address.
+
+    >>> decimal_to_ip(3232235521)
+    '192.168.0.1'
+    >>> decimal_to_ip(167772415)
+    '10.0.0.255'
+    """
+
+    if not (0 <= decimal_ip <= 4294967295):
path: conversions/ipconversion.py
text: @user1:
This would not catch 10.0.0.256 which is not a valid IP.

diff_hunk: @@ -0,0 +1,62 @@
+# https://www.geeksforgeeks.org/convert-ip-address-to-integer-and-vice-versa/
+
+
+def ip_to_decimal(ip_address: str) -> int:
+    """
+    Convert an IPv4 address to its decimal representation.
+
+    Args:
+        ip_address (str): A string representing an IPv4 address (e.g., "192.168.0.1").
+
+    Returns:
+        int: The decimal representation of the IP address.
+
+    >>> ip_to_decimal("192.168.0.1")
+    3232235521
+    >>> ip_to_decimal("10.0.0.255")
+    167772415
+    """
+
+    ip_parts = ip_address.split(".")
+    if len(ip_parts) != 4:
+        raise ValueError("Invalid IPv4 address format")
+
+    decimal_ip = 0
+    for part in ip_parts:
+        decimal_ip = (decimal_ip << 8) + int(part)
+
+    return decimal_ip
path: conversions/ipconversion.py
text: @user1:
```
def alt_ip_to_decimal(ip_address: str) -> int:
    return int("0x" + "".join(f"{int(i):02x}" for i in ip_address.split(".")), 16)
```