For solving the left-side trailing zero problem:
my_hexdata = "1a"
scale = 16 ## equals to hexadecimal
num_of_bits = 8
bin(int(my_hexdata, scale))[2:].zfill(num_of_bits)
It will give 00011010 instead of the trimmed version.
More Related Contents:
- How do I print curly-brace characters in a string while using .format?
- What does the ‘b’ character do in front of a string literal?
- Convert hex string to int in Python
- How can I fill out a Python string with spaces?
- How to convert string to binary?
- How to convert ‘binary string’ to normal string in Python3?
- Print a string as hexadecimal bytes
- Convert hex string to integer in Python
- Convert hex to float
- How to convert an int to a hex string?
- Format string unused named arguments [duplicate]
- Python 3.1.1 string to hex
- Remove ‘b’ character do in front of a string literal in Python 3 [duplicate]
- How can I extract keywords from a Python format string?
- When to use %r instead of %s in Python? [duplicate]
- How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?
- Plural String Formatting
- How can I use f-string with a variable, not with a string literal?
- How do I format a number with a variable number of digits in Python?
- Slicing strings in str.format
- Reading binary file and looping over each byte
- Converting integer to string in Python
- Converting integer to binary in python
- Get last “column” after .str.split() operation on column in pandas DataFrame
- How to left align a fixed width string?
- Converting a string that represents a list, into an actual list object
- How to concatenate (join) items in a list to a single string
- Using Python’s Format Specification Mini-Language to align floats
- f.read coming up empty
- How to remove all integer values from a list in python