It converts HL to any base from 2 to 36 and uses the OS ASCII for the numbers and letters (which match the tokens). This can be easily modified to handle 32-bit input, too:
;=================================================================
ConvNumBase:
;=================================================================
;Inputs:
; C is the base to convert to
; HL is the number to convert
;Output:
; A is the number of digits
; BC is the number of digits
; DE is 0
; HL points to the number string
;Notes:
; This converts HL to a zero terminated string stored in OP4
; and possibly a few bytes of OP3.
;=================================================================
xor a
ld de,84A3h
ld (de),a
dec de
call HL_Div_C
cp 10
jr c,$+4
add a,7
add a,48
ld (de),a
dec de
ld a,h
or l
jr nz,$-15
ld a,$A2
sub e
ld c,a
inc de
ex de,hl
ret