From f4b8067b7ce6f447b04d66f24c00a5becbc50c73 Mon Sep 17 00:00:00 2001 From: Heyyayaya <116991476+Heyyayaya@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:50:53 +0530 Subject: [PATCH 1/2] Create decimal-converter-to-binary.py This contains a decimal-binary converting python code where it includes a sample output as a comment to get an idea of how it looks likes at the output. --- Dev/decimal-converter-to-binary.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Dev/decimal-converter-to-binary.py diff --git a/Dev/decimal-converter-to-binary.py b/Dev/decimal-converter-to-binary.py new file mode 100644 index 0000000..7e72e1e --- /dev/null +++ b/Dev/decimal-converter-to-binary.py @@ -0,0 +1,25 @@ +def dec2bin(number: int): + ans = "" + if ( number == 0 ): + return 0 + while ( number ): + ans += str(number&1) + number = number >> 1 + + ans = ans[::-1] + + return ans + + +def main(): + number = 10 + print(f"The binary of the number {number} is {dec2bin(number)}") + + +# code driver +if __name__ == "__main__": + main() + + // Sample output +//you will get a answer like as below +//The binary of the number 10 is 1010 From 5f305cc6d7686bd77be221ea0ee24be212ebe95e Mon Sep 17 00:00:00 2001 From: Heyyayaya <116991476+Heyyayaya@users.noreply.github.com> Date: Sun, 30 Oct 2022 23:01:59 +0530 Subject: [PATCH 2/2] Update decimal-converter-to-binary.py --- Dev/decimal-converter-to-binary.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dev/decimal-converter-to-binary.py b/Dev/decimal-converter-to-binary.py index 7e72e1e..db23409 100644 --- a/Dev/decimal-converter-to-binary.py +++ b/Dev/decimal-converter-to-binary.py @@ -20,6 +20,6 @@ def main(): if __name__ == "__main__": main() - // Sample output -//you will get a answer like as below -//The binary of the number 10 is 1010 +#Sample display +#you will get a answer like as below +#The binary of the number 10 is 1010