![]() | the sleepy snakeindex :: num :: to_base | |||||||
to_base(to_base, num, base=10)onverts a number or string to a number of the given base
Retuns: the resulting number as string Note: The function handles hexadecimal strings prefixed with HEX_PREFIXES as defined in the module aswell, as long as the correct base (16) is specified # convert string containng hex number to binary bin = to_base(2, '0xff', base=16) >> '11111111' # convert from any base to bytes and back again integer = 255 bytes = to_base(256, integer, base=10) print bytes >> ''\xff'' bits = to_base(2, bytes, base=255) print bits >> '11111111' | ||||||||