From d3fd7857e960203254f99cab145967e80755f4fe Mon Sep 17 00:00:00 2001 From: Sarthak Joshi <100042684+Craniace@users.noreply.github.com> Date: Fri, 31 Oct 2025 23:36:53 +0530 Subject: [PATCH 1/2] Create bianry_to_excessthree.py --- conversions/bianry_to_excessthree.py | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 conversions/bianry_to_excessthree.py diff --git a/conversions/bianry_to_excessthree.py b/conversions/bianry_to_excessthree.py new file mode 100644 index 000000000000..a2397f9797b3 --- /dev/null +++ b/conversions/bianry_to_excessthree.py @@ -0,0 +1,30 @@ +def binary_to_excess3(binary_str: str) -> str: + """ + Convert a binary number (as a string) to its Excess-3 code. + + Args: + binary_str (str): Binary number as a string (e.g., "1010"). + + Returns: + str: Excess-3 code as a binary string. + + Example: + >>> binary_to_excess3("1010") + '1101' + """ + # Convert binary to decimal + decimal_value = int(binary_str, 2) + + # Add 3 (Excess-3 encoding) + excess3_value = decimal_value + 3 + + # Convert back to 4-bit binary + excess3_binary = format(excess3_value, '04b') + + return excess3_binary + + +if __name__ == "__main__": + binary_input = input("Enter a 4-bit binary number: ") + excess3_output = binary_to_excess3(binary_input) + print(f"Excess-3 code of {binary_input} is: {excess3_output}") From 5ccc7319af713e728e31f0ffce9cace76f47b768 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 31 Oct 2025 18:09:08 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- conversions/bianry_to_excessthree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/bianry_to_excessthree.py b/conversions/bianry_to_excessthree.py index a2397f9797b3..58a10501f421 100644 --- a/conversions/bianry_to_excessthree.py +++ b/conversions/bianry_to_excessthree.py @@ -19,7 +19,7 @@ def binary_to_excess3(binary_str: str) -> str: excess3_value = decimal_value + 3 # Convert back to 4-bit binary - excess3_binary = format(excess3_value, '04b') + excess3_binary = format(excess3_value, "04b") return excess3_binary