"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n%b]
instead of 
if (remain <= 9)
    result[p] = (char)('0' + remain);
else
	result[p] = (char)('A' + remain - 10);