Pyou
Pyou

Reputation: 13

Convert 0x000F to "0F" in python basically trying to convert to ASCII string

How to convert hexadecimal value 0x000F into string value "0F" in python? Basically, I've been trying to convert number to string.

Upvotes: 0

Views: 194

Answers (1)

Barmar
Barmar

Reputation: 781731

Use % formatting:

str = "%02x" % 0x000F

%x formatting means to format as a float, the 02 prefix means to put it in a 2-digit field with zero padding.

Upvotes: 3

Related Questions