Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def decode_sex(sex_value: str) -> str:
- """
- Decode from Sexadecimal to Hexadecimal
- """
- minus = "-"
- if sex_value[0] == minus:
- sex_value = sex_value[1:]
- negative = True
- else:
- negative = False
- digits = "0123456789KSNJFL"
- result = 0
- for index, digit in enumerate(reversed(sex_value)):
- result += digits.index(digit.upper()) * 16 ** index
- if negative:
- result *= -1
- return f"{result:x}"
- def encode_sex(hex_value: str) -> str:
- """
- Encode Hexadecimal to Sexadecimal
- """
- minus = "-"
- if hex_value[0] == minus:
- hex_value = hex_value[1:]
- prefix = minus
- else:
- prefix = ""
- result = []
- digits = "0123456789KSNJFL"
- value = int(hex_value, 16)
- rest = 0
- while value:
- result.append(digits[value % 16])
- value //= 16
- return prefix + "".join(reversed(result))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement