From 8079d344c35a0f580cf41636c923fb743d1c9770 Mon Sep 17 00:00:00 2001 From: Joydip104 Date: Mon, 16 Mar 2026 13:28:18 +0530 Subject: [PATCH 01/10] Init branch readme --- readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e965047 --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +Hello From 34c3163555d5154697995dbb6c0f21092df19eb9 Mon Sep 17 00:00:00 2001 From: Joydip104 Date: Mon, 16 Mar 2026 14:56:23 +0530 Subject: [PATCH 02/10] Init hex.py and test_hex.py --- hex.py | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test_hex.py | 72 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 hex.py create mode 100644 test_hex.py diff --git a/hex.py b/hex.py new file mode 100644 index 0000000..a7a2fa8 --- /dev/null +++ b/hex.py @@ -0,0 +1,90 @@ +class HexCalculator: + """ + Hexadecimal calculator module. + + Supports: + - Hex ↔ Decimal conversions + - Arithmetic operations in HEX + - Complement calculations + - Input validation + """ + + def _validate_hex(self, value: str) -> str: + """ + Validate input format H'AB12' + Returns the internal hex string. + """ + if not isinstance(value, str): + raise ValueError("Input must be a string") + + if not value.startswith("H'") or not value.endswith("'"): + raise ValueError("Invalid HEX format. Expected H'AB12'") + + hex_part = value[2:-1] + + try: + int(hex_part, 16) + except ValueError: + raise ValueError("Invalid hexadecimal digits") + + return hex_part + + # ------------------------------- + # Sravanti will edit this part + # ------------------------------- + def hex_to_decimal(self, value: str) -> str: + """ + Convert HEX → Decimal + + Example: + H'1A5' → D'421' + """ + raise NotImplementedError("hex_to_decimal not implemented yet") + + # ------------------------------- + # Saichaitanya will edit this part + # ------------------------------- + def decimal_to_hex(self, value: str) -> str: + """ + Convert Decimal → HEX + + Example: + D'243' → H'F3' + """ + raise NotImplementedError("decimal_to_hex not implemented yet") + + # ------------------------------- + # Joydip will edit this part + # ------------------------------- + def add(self, a: str, b: str) -> str: + """ + HEX addition + + Example: + H'A' + H'5' → H'F' + """ + raise NotImplementedError("add not implemented yet") + # ------------------------------- + # Pratyush will edit this part + # ------------------------------- + + def subtract(self, a: str, b: str) -> str: + """ + HEX subtraction + """ + raise NotImplementedError("subtract not implemented yet") + + # ------------------------------- + # Sneha will edit this part + # ------------------------------- + def fifteen_complement(self, value: str) -> str: + """ + Compute 15's complement + """ + raise NotImplementedError("15's complement not implemented yet") + + def sixteen_complement(self, value: str) -> str: + """ + Compute 16's complement + """ + raise NotImplementedError("16's complement not implemented yet") \ No newline at end of file diff --git a/test_hex.py b/test_hex.py new file mode 100644 index 0000000..fd00360 --- /dev/null +++ b/test_hex.py @@ -0,0 +1,72 @@ +# test_hex.py + +import unittest +from hex import HexCalculator + + +class TestHexCalculator(unittest.TestCase): + + def setUp(self): + self.hex_calc = HexCalculator() + + # --------------------------------- + # SRAVANTI 1 TESTS + # --------------------------------- + def test_hex_to_decimal(self): + self.assertEqual( + self.hex_calc.hex_to_decimal("H'1A5'"), + "D'421'" + ) + + # --------------------------------- + # SAICHAITANYA 2 TESTS + # --------------------------------- + def test_decimal_to_hex(self): + self.assertEqual( + self.hex_calc.decimal_to_hex("D'243'"), + "H'F3'" + ) + + # --------------------------------- + # JOYDIP 3 TESTS + # --------------------------------- + def test_add(self): + self.assertEqual( + self.hex_calc.add("H'A'", "H'5'"), + "H'F'" + ) + # --------------------------------- + # PRATYUSH 3 TESTS + # --------------------------------- + + def test_subtract(self): + self.assertEqual( + self.hex_calc.subtract("H'F'", "H'5'"), + "H'A'" + ) + + # --------------------------------- + # SNEHA 4 TESTS + # --------------------------------- + def test_fifteen_complement(self): + self.assertEqual( + self.hex_calc.fifteen_complement("H'A'"), + "H'5'" + ) + + def test_sixteen_complement(self): + self.assertEqual( + self.hex_calc.sixteen_complement("H'A'"), + "H'6'" + ) + + # --------------------------------- + # COMMON VALIDATION TEST --- Already Done + # --------------------------------- + def test_invalid_hex(self): + with self.assertRaises(ValueError): + self.hex_calc.hex_to_decimal("123") + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From c9df2d32206399057cbf2942812c9bd1e81651e9 Mon Sep 17 00:00:00 2001 From: Pratyush Dhital Date: Sat, 28 Mar 2026 16:29:16 +0530 Subject: [PATCH 03/10] added the substract function with the test cases --- hex.py | 10 +++++++++- test_hex.py | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hex.py b/hex.py index a7a2fa8..b7fca31 100644 --- a/hex.py +++ b/hex.py @@ -72,7 +72,15 @@ def subtract(self, a: str, b: str) -> str: """ HEX subtraction """ - raise NotImplementedError("subtract not implemented yet") + hex_a = self._validate_hex(a) + hex_b = self._validate_hex(b) + + result = int(hex_a, 16) - int(hex_b, 16) + + if result < 0: + return f"H'-{format(abs(result), 'X')}'" + + return f"H'{format(result, 'X')}'" # ------------------------------- # Sneha will edit this part diff --git a/test_hex.py b/test_hex.py index fd00360..c567b5d 100644 --- a/test_hex.py +++ b/test_hex.py @@ -45,6 +45,18 @@ def test_subtract(self): "H'A'" ) + def test_subtract_with_borrow(self): + self.assertEqual( + self.hex_calc.subtract("H'10'", "H'1'"), + "H'F'" + ) + + def test_subtract_negative_result(self): + self.assertEqual( + self.hex_calc.subtract("H'2'", "H'5'"), + "H'-3'" + ) + # --------------------------------- # SNEHA 4 TESTS # --------------------------------- From 534b46fd810270050188b9316f80b86e205a469a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sneha-=C2=84Das1?= Date: Sat, 28 Mar 2026 20:43:37 +0530 Subject: [PATCH 04/10] Added complement functions --- hex.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/hex.py b/hex.py index a7a2fa8..b5eacf3 100644 --- a/hex.py +++ b/hex.py @@ -74,6 +74,11 @@ def subtract(self, a: str, b: str) -> str: """ raise NotImplementedError("subtract not implemented yet") + # ------------------------------- + # Sneha will edit this part + # ------------------------------- + class HexCalculator: + # ------------------------------- # Sneha will edit this part # ------------------------------- @@ -81,10 +86,32 @@ def fifteen_complement(self, value: str) -> str: """ Compute 15's complement """ - raise NotImplementedError("15's complement not implemented yet") + hex_part = self._validate_hex(value) + + result = "" + for digit in hex_part: + comp = 15 - int(digit, 16) + result += format(comp, 'X') + + return f"H'{result}'" + def sixteen_complement(self, value: str) -> str: """ Compute 16's complement """ - raise NotImplementedError("16's complement not implemented yet") \ No newline at end of file + hex_part = self._validate_hex(value) + + # Step 1: 15's complement + comp15 = "" + for digit in hex_part: + comp = 15 - int(digit, 16) + comp15 += format(comp, 'X') + + # Step 2: add 1 + comp16 = hex(int(comp15, 16) + 1)[2:].upper() + + # Step 3: maintain same length + comp16 = comp16.zfill(len(hex_part)) + + return f"H'{comp16}'" \ No newline at end of file From 68c6bc9ac1a718b4eebdea91361d2374b2e3cd27 Mon Sep 17 00:00:00 2001 From: Pratyush Dhital <143419336+pratyush-dhital@users.noreply.github.com> Date: Mon, 30 Mar 2026 14:17:56 +0530 Subject: [PATCH 05/10] Remove HexCalculator class definition Removed redundant HexCalculator class definition from hex.py --- hex.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/hex.py b/hex.py index 2339140..7a73284 100644 --- a/hex.py +++ b/hex.py @@ -82,11 +82,6 @@ def subtract(self, a: str, b: str) -> str: return f"H'{format(result, 'X')}'" - # ------------------------------- - # Sneha will edit this part - # ------------------------------- - class HexCalculator: - # ------------------------------- # Sneha will edit this part # ------------------------------- @@ -122,4 +117,4 @@ def sixteen_complement(self, value: str) -> str: # Step 3: maintain same length comp16 = comp16.zfill(len(hex_part)) - return f"H'{comp16}'" \ No newline at end of file + return f"H'{comp16}'" From a7b45d35d5c9019708f4f068d79e1cbb9810caf0 Mon Sep 17 00:00:00 2001 From: saichaithanya12 Date: Mon, 30 Mar 2026 15:23:39 +0530 Subject: [PATCH 06/10] added the decimal to hex conversion --- hex.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hex.py b/hex.py index 7a73284..dbd99fd 100644 --- a/hex.py +++ b/hex.py @@ -45,14 +45,15 @@ def hex_to_decimal(self, value: str) -> str: # Saichaitanya will edit this part # ------------------------------- def decimal_to_hex(self, value: str) -> str: - """ - Convert Decimal → HEX + value = value.strip() - Example: - D'243' → H'F3' - """ - raise NotImplementedError("decimal_to_hex not implemented yet") + if value.startswith("D'") and value.endswith("'"): + value = value[2:-1] + + if not value.isdigit(): + raise ValueError("Invalid decimal input") + return f"H'{hex(int(value))[2:].upper()}'" # ------------------------------- # Joydip will edit this part # ------------------------------- From 3c1fa58e789857fb343e55c4fb9c7d65d6f4194f Mon Sep 17 00:00:00 2001 From: Sai chaithanya Date: Mon, 6 Apr 2026 15:02:56 +0530 Subject: [PATCH 07/10] Add tests for decimal to hex conversion --- test_hex.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test_hex.py b/test_hex.py index c567b5d..1f43b67 100644 --- a/test_hex.py +++ b/test_hex.py @@ -26,6 +26,14 @@ def test_decimal_to_hex(self): self.hex_calc.decimal_to_hex("D'243'"), "H'F3'" ) + def test_decimal_to_hex_small(self): + self.assertEqual( + self.hex_calc.decimal_to_hex("D'15'"), + "H'F'" + ) + def test_decimal_to_hex_invalid_chars(self): + with self.assertRaises(ValueError): + self.hex_calc.decimal_to_hex("D'12A'") # --------------------------------- # JOYDIP 3 TESTS @@ -81,4 +89,4 @@ def test_invalid_hex(self): if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() From 159fda6bd3933a8e342a86ef43f71a8961a6967b Mon Sep 17 00:00:00 2001 From: Sai chaithanya Date: Mon, 6 Apr 2026 15:04:14 +0530 Subject: [PATCH 08/10] Update test_hex.py --- test_hex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_hex.py b/test_hex.py index 1f43b67..643f684 100644 --- a/test_hex.py +++ b/test_hex.py @@ -19,7 +19,7 @@ def test_hex_to_decimal(self): ) # --------------------------------- - # SAICHAITANYA 2 TESTS + # SAICHAITANYA 3 TESTS # --------------------------------- def test_decimal_to_hex(self): self.assertEqual( From 606d137674e593e84fe9a1e3eb2d4e1ad20ec39f Mon Sep 17 00:00:00 2001 From: Sai chaithanya Date: Mon, 6 Apr 2026 15:26:17 +0530 Subject: [PATCH 09/10] Modify test cases for SAICHAITANYA Updated test cases for decimal to hex conversion. --- test_hex.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test_hex.py b/test_hex.py index 643f684..7f79209 100644 --- a/test_hex.py +++ b/test_hex.py @@ -19,7 +19,7 @@ def test_hex_to_decimal(self): ) # --------------------------------- - # SAICHAITANYA 3 TESTS + # SAICHAITANYA 2 TESTS # --------------------------------- def test_decimal_to_hex(self): self.assertEqual( @@ -31,10 +31,6 @@ def test_decimal_to_hex_small(self): self.hex_calc.decimal_to_hex("D'15'"), "H'F'" ) - def test_decimal_to_hex_invalid_chars(self): - with self.assertRaises(ValueError): - self.hex_calc.decimal_to_hex("D'12A'") - # --------------------------------- # JOYDIP 3 TESTS # --------------------------------- From 361024af728c0436c855dd3160207fdec6036889 Mon Sep 17 00:00:00 2001 From: Sai chaithanya Date: Mon, 6 Apr 2026 15:27:06 +0530 Subject: [PATCH 10/10] Fix indentation in test_decimal_to_hex_small --- test_hex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_hex.py b/test_hex.py index 7f79209..ef6c4dd 100644 --- a/test_hex.py +++ b/test_hex.py @@ -30,7 +30,7 @@ def test_decimal_to_hex_small(self): self.assertEqual( self.hex_calc.decimal_to_hex("D'15'"), "H'F'" - ) + ) # --------------------------------- # JOYDIP 3 TESTS # ---------------------------------