From c91d5acdc1f712703cdd8e074fc8c39b3a5d2728 Mon Sep 17 00:00:00 2001 From: tasbihaasim Date: Wed, 7 Oct 2020 16:32:56 +0500 Subject: [PATCH] Add convert_to_binary snippet --- snippets/convert_to_binary.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/convert_to_binary.md diff --git a/snippets/convert_to_binary.md b/snippets/convert_to_binary.md new file mode 100644 index 000000000..9c6d4fc00 --- /dev/null +++ b/snippets/convert_to_binary.md @@ -0,0 +1,17 @@ +--- +title: arithmetic_progression +tags: math,beginner +--- + +Returns the base 2 equivalent of a decimal number + +- Use `bin` to convert a given decimal number into binary equivalent + +```py +def convert_to_binary(n): + return bin(n) +``` + +```py +convert_to_binary(100) # 0b1100100 +``` \ No newline at end of file