Conversion between binary, hexadecimal and decimal numbers using Coden module

The coden is a Python library developed by Tanmay Earappa for handling secret codes and number base conversions. This module provides convenient functions to convert between binary, hexadecimal, and decimal number systems.

Installation

Install the coden module using pip ?

pip install coden

Key Conversion Functions

The coden module provides the following conversion functions ?

  • hex_to_bin(): Converts hexadecimal to binary

  • hex_to_int(): Converts hexadecimal to decimal

  • bin_to_hex(): Converts binary to hexadecimal

  • bin_to_int(): Converts binary to decimal

  • int_to_bin(): Converts decimal to binary

  • int_to_hex(): Converts decimal to hexadecimal

Hexadecimal to Binary Conversion

The hex_to_bin() function converts a hexadecimal number to its binary representation ?

import coden

hexadecimal_number = "f1ff"
print("Input Hexadecimal Number:", hexadecimal_number)

binary_output = coden.hex_to_bin(hexadecimal_number)
print("Binary Output:", binary_output)
Input Hexadecimal Number: f1ff
Binary Output: 1111000111111111

Hexadecimal to Decimal Conversion

The hex_to_int() function converts a hexadecimal number to decimal ?

import coden

hexadecimal_number = "f1ff63"
print("Input Hexadecimal Number:", hexadecimal_number)

decimal_number = coden.hex_to_int(hexadecimal_number)
print("Decimal Output:", decimal_number)
Input Hexadecimal Number: f1ff63
Decimal Output: 15859555

Binary to Hexadecimal Conversion

The bin_to_hex() function converts binary numbers to hexadecimal format ?

import coden

binary_number = "001010101111000001001000111110111111111111"
print("Input Binary Number:", binary_number)

hexadecimal_output = coden.bin_to_hex(binary_number)
print("Hexadecimal Output:", hexadecimal_output)
Input Binary Number: 001010101111000001001000111110111111111111
Hexadecimal Output: abc123efff

Decimal to Binary Conversion

Use int_to_bin() to convert decimal numbers to binary ?

import coden

decimal_number = 16227
print("Input Decimal Number:", decimal_number)

binary_output = coden.int_to_bin(decimal_number)
print("Binary Output:", binary_output)
Input Decimal Number: 16227
Binary Output: 11111101100011

Decimal to Hexadecimal Conversion

The int_to_hex() function converts decimal numbers to hexadecimal ?

import coden

decimal_number = 16227
print("Input Decimal Number:", decimal_number)

hexadecimal_output = coden.int_to_hex(decimal_number)
print("Hexadecimal Output:", hexadecimal_output)
Input Decimal Number: 16227
Hexadecimal Output: 3f63

Binary to Decimal Conversion

The bin_to_int() function performs binary to decimal conversion ?

import coden

binary_number = "001010101111000001001000111110111111111111"
print("Input Binary Number:", binary_number)

decimal_output = coden.bin_to_int(binary_number)
print("Decimal Output:", decimal_output)
Input Decimal Number: 001010101111000001001000111110111111111111
Decimal Output: 737679765503

Conversion Summary

From To Function
Hexadecimal Binary hex_to_bin()
Hexadecimal Decimal hex_to_int()
Binary Hexadecimal bin_to_hex()
Binary Decimal bin_to_int()
Decimal Binary int_to_bin()
Decimal Hexadecimal int_to_hex()

Conclusion

The coden module simplifies number base conversions with intuitive function names. It provides a convenient alternative to Python's built-in conversion methods for binary, hexadecimal, and decimal transformations.

Updated on: 2026-03-27T06:49:25+05:30

291 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements