Given a number N in decimal base, the task is to find the sum of digits of the number in any base B.
Input: N = 100, B = 8
(100)8 = 144
Sum(144) = 1 + 4 + 4 = 9
Input: N = 50, B = 2
(50)2 = 110010
Sum(110010) = 1 + 1 + 0 + 0 + 1 + 0 = 3
Approach: Find unit digit by performing modulo operation on number N by base B and updating the number again by N = N / B and update sum by adding the unit digit at each step.
Below is the implementation of above approach
- 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
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- Check if the number is even or odd whose digits and base (radix) is given
- Check if a given number can be represented in given a no. of digits in any base
- Convert from any base to decimal and vice versa
- Convert all substrings of length 'k' from base 'b' to decimal
- All possible numbers of N digits and base B without leading zeros
- Program to find the last digit of X in base Y
- Pandigital number in a given base
- Complement of a number with any base b
- Check if a number is in given base or not
- Check whether a number has consecutive 0's in the given base or not
- Number System and Base Conversions
- Check if a number N starts with 1 in b-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 firstname.lastname@example.org. 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.