Find most significant bit of a number X in base Y | Python3 program to find the first digit of X in base Y ; Function to find the first digit of X in base Y ; Calculating number of digits of x in base y ; Finding first digit of x in base y ; Driver code
import math NEW_LINE def first_digit ( x , y ) : NEW_LINE INDENT length = int ( math . log ( x ) / math . log ( y ) + 1 ) NEW_LINE first_digit = x / math . pow ( y , length - 1 ) NEW_LINE print ( int ( first_digit ) ) NEW_LINE DEDENT X = 55 NEW_LINE Y = 3 NEW_LINE first_digit ( X , Y ) NEW_LINE