If our true goal was to get the hexadecimal value of 42 this would be a silly example-we’d just skip the bin() function altogether as such: hex(42). Consider how the official Python documentation describes its use:Ĭonvert an integer number to a lowercase hexadecimal string prefixed with “0x”. So that isn’t great news but it is expected behavior given the implementation of the hex() function. TypeError: 'str' object cannot be interpreted as an integer For example, let’s try to convert a binary string to a hexadecimal value: # Convert to hexadecimal Python’s bin() function will show you the binary representation of a number but there isn’t a lot you can do with that information explicitly. ![]()
0 Comments
Leave a Reply. |