Change base algorithm