Calculating the number ( n ) by taking mod with the base and adding remainder to the result and parallelly reducing the num value .
while ( $ n > 0 ) { $ remainder = $ n % $ base ; $ result = $ result + $ remainder ; $ n = $ n / $ base ; }