hexdutils is a small but useful Python library to deal with hexadecimals. Int to hex, hex to int, text-to-hex, operations between hex.
The code is in dev branch.
Function names are very clear by themselves, but here's a guide.
Returns a the hex value of a number as a string.
- Arguments:
- Mandatory:
intnumber: the integer to convert;
- Optional:
boolhex_prefix: adds "0x" at the beginning of the output, like the nativehexPython function. Set as False by default;booluppercase: every letter in the output is uppercased. Set as False by default;
- Mandatory:
Returns the value of an hex as an integer.
- Arguments:
- Mandatory:
strtarget: the hex value to convert. Accepts also "0x" values;
- Mandatory:
Returns text converted in hex. Randomization available.
- Arguments
- Mandatory:
strtarget: text to convert;
- Optional:
strconversion: the letter values to be used. "alphabet" uses the position of each letter in the alphabet to assign an integer value (e.g a=1, b=2, etc.). "ord" uses the result oford(letter)(e.gord("a") = 97). Set as "ord" by default:boolverbose: if True, some additional logs will be printed. Set as False by defaultbool|strprefix: if set as True, the "0x" prefix will be added to the output. Also, you can type a custom prefix and it will be added. Set as False by default.bool|strindividual_prefix: if set only as True, each hex value in the output will have the "0x" prefix. Likeprefix, you can set this value to a custom prefix string, and use it instead of "0x". Requiresprefix=Trueto work. Set as False by default
- Mandatory:
- Arguments:
- Mandatory:
strtarget: hex value to convert to text.
- Mandatory:
| Function | Operator |
|---|---|
| hex_add | + |
| hex_subtract | - |
| hex_multiply | * |
| hex_divide | / |
| hex_floor | // |
| hex_mod | % |
| hex_power | ** |
Usage: operation(<str>value_one, <str>value_two, [<bool>hex_output, <bool>hex_output_prefix. <bool>hex_output_upper])
The arguments for those functions are all the same:
-
Mandatory:
strvalue_one;strvalue_two;boolhex_output: if set as True, the operation result will be returned as an hex value. If set as False, an integer will be returned;
-
Optional:
boolhex_output_prefix: If set as True, adds "0x" at the beginning of the output. Set as False by default;boolhex_output_upper: If set as True, every letter in the output is uppercased. Set as False by default;
Open an issue 🆘
Open a pull request 📥