Coden is a library based on codes, secret codes. This library can be used for encoding and decoding so that a message can be sent secretly. It can also be used for conversion between binary, hexadecimal and decimal numbers in Python.
Installation
This module does not comes built-in with Python. To install it type the below command in the terminal.
pip install coden
Conversion between binary, hexadecimal and decimal numbers
Decimal to Binary: This module provides a built-int method called int_to_bin() for doing the same.
Example:
Python3
import coden a_decimal_number = 16227binary_output = coden.int_to_bin(a_decimal_number) print(binary_output) |
Output:
11111101100011
Decimal to Hexadecimal: This module provides a built-int method called int_to_hex() for doing the same.
Example:
Python3
import coden a_decimal_number = 165hexadecimal_output = coden.int_to_hex(a_decimal_number) print(hexadecimal_output) |
Output:
a5
Binary to Hexadecimal: This module provides a built-int method called bin_to_hex() for doing the same.
Example:
Python3
import coden a_binary_number = 110100hexadecimal_output = coden.bin_to_hex(a_binary_number) print(hexadecimal_output) |
Output:
34
Binary to Decimal: This module provides a built-int method called bin_to_int() for doing the same.
Example:
Python3
import coden a_binary_number = 10010decimal_output = coden.bin_to_int(a_binary_number) print(decimal_output) |
Output:
18
Hexadecimal to Binary: This module provides a built-int method called hex_to_bin() for doing the same.
Example:
Python3
import coden a_hexadecimal_number = "f1ff"binary_output = coden.hex_to_bin(a_hexadecimal_number) print(binary_output) |
Output:
1111000111111111
Hexadecimal to Decimal: This module provides a built-int method called hex_to_int() for doing the same.
Example:
Python3
import coden a_hexadecimal_number = "ffea1a"decimal_output = coden.hex_to_int(a_hexadecimal_number) print(decimal_output) |
Output:
16771610
Random Numbers using coden module
Random hexadecimal: The function randoms.hexadecimal returns a random hexadecimal number between the given range of hexadecimal numbers.
Example:
Python3
import coden a = "f"b = "1e" # returns random hexadecimal in range # of a - b. random_hexadecimal_output = coden.randoms.hexadecimal(a, b) print(random_hexadecimal_output) |
Output:
15
Random binary: The function randoms.binary returns a random binary number between the given range of binary numbers.
Example:
Python3
import coden a = 101b = 10101 # returns random binary in range # of a - b. random_hexadecimal_output = coden.randoms.binary(a, b) print(random_hexadecimal_output) |
Output:
110
Random Hexadecimal Color: randoms.hexcolor() returns a random hexadecimal number(color).
Example:
Python3
import coden # returns random hexadecimal color random_hexadecimal_color_output = coden.randoms.hexcolor() print(random_hexadecimal_color_output) |
Output:
#63783A
Recommended Posts:
- Python | Decimal to binary list conversion
- Converting Roman to Decimal in Python using gnboorse-rom module
- Python | Convert Bytearray to Hexadecimal String
- Python program to represent floating number as hexadecimal by IEEE 754 standard
- Binary to decimal and vice-versa in python
- What is the difference between Python's Module, Package and Library?
- Python: Weight Conversion GUI using Tkinter
- Stack and Queue in Python using queue Module
- Python | Adjusting rows and columns of an excel file using openpyxl module
- Python | Create and write on excel file using xlsxwriter module
- Operations on Graph and Special Graphs using Networkx module | Python
- Remember and copy passwords to clipboard using Pyperclip module in Python
- Python - Get Hardware and System information using platform module
- Priority Queue using Queue and Heapdict module in Python
- Secrets | Python module to Generate secure random numbers
- Python program to convert decimal to binary number
- HTML Cleaning and Entity Conversion | Python
- Python - Type conversion in Nested and Mixed List
- Python | Writing to an excel file using openpyxl module
- Count frequencies of all elements in array in Python using collections module
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

