Given two positive integers X and Y, the task is to find the MSB of X, in the given base Y.
Input: X = 55, Y = 3
55 is 2001 in base 3 with first digit as 2.
Input: X = 123, Y = 10
123 is 123 in base 10 with first digit 1.
Approach: Let the task to find 1st digit of X = 1234 in base Y = 10, So to get First digit = 1:
Divide 1234 by 1000
= X / 103
= X / 10Number of Digits in X – 1
= X / 10log(X) / log(10) (which is for base 10)
For any other base, we can replace 10 with Y. Therefore, we can calculate the first digit of a number X in base Y by using the formula:
X / Y(log(X)/log(Y))
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Given a number N in decimal base, find number of its digits in any base (base b)
- Find the Nth digit from right in base B of the given number in Decimal base
- Given a number N in decimal base, find the sum of digits in any base B
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- Find the length of factorial of a number in any given base
- Find the Largest N digit perfect square number in Base B
- Round-off a number to a given number of significant digits
- Program to find the last digit of X in base Y
- Add two integers of different base and represent sum in smaller base of the two
- Check if a number is in given base or not
- Check if a N base number is Even or Odd
- Complement of a number with any base b
- Pandigital number in a given base
- Find the total count of numbers up to N digits in a given base B
- Largest value of x such that axx is N-digit number of base b
- Largest N digit number in Base B
- Check if a number N starts with 1 in b-base
- Check whether a number has consecutive 0's in the given base or not
- Number System and Base Conversions
- Find the height of a right-angled triangle whose area is X times its base
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.