conversions.hex_to_bin

Functions

hex_to_bin(→ int)

Convert a hexadecimal value to its binary equivalent

Module Contents

conversions.hex_to_bin.hex_to_bin(hex_num: str) int

Convert a hexadecimal value to its binary equivalent #https://stackoverflow.com/questions/1425493/convert-hex-to-binary Here, we have used the bitwise right shift operator: >> Shifts the bits of the number to the right and fills 0 on voids left as a result. Similar effect as of dividing the number with some power of two. Example: a = 10 a >> 1 = 5

>>> hex_to_bin("AC")
10101100
>>> hex_to_bin("9A4")
100110100100
>>> hex_to_bin("   12f   ")
100101111
>>> hex_to_bin("FfFf")
1111111111111111
>>> hex_to_bin("-fFfF")
-1111111111111111
>>> hex_to_bin("F-f")
Traceback (most recent call last):
    ...
ValueError: Invalid value was passed to the function
>>> hex_to_bin("")
Traceback (most recent call last):
    ...
ValueError: No value was passed to the function