3

I know it is simple and possible to convert any base to any base. First, convert any base to decimal and then decimal to any other base. However, I had done this before for range 2 to 36 but never done for 2 to 46.

I don't understand what I will put after 36, because 36 means 'z' (1-10 are decimal numbers then the 26 characters of the alphabet).

Please explains what happens after 36.

phant0m
  • 16,595
  • 5
  • 50
  • 82
user1542653
  • 439
  • 2
  • 6
  • 16
  • 7
    At some point, you just have to invent symbols or use ones from other alphabets. – juanchopanza Sep 25 '12 at 06:30
  • 3
    Or use uppercase letters as in Base64 encoding. – L.B Sep 25 '12 at 06:31
  • 1
    you mean first I should add 26 chars from lower case alphabets and then another 10 digits from upper case... Am I right? – user1542653 Sep 25 '12 at 06:35
  • 6
    You don't need to convert to decimal before converting to other base. I guess it will be easier because you are used to calculating in base 10 but it is not necessary. As for the digit symbols just invent some – Ivaylo Strandjev Sep 25 '12 at 06:35
  • just use (aa)(ab)(a...)(az)(ba)(bb)(b...)(bz)(...)(za)(zb)(z...)(zz) as the digits :-) – Johannes Schaub - litb Sep 25 '12 at 06:42
  • Then why not (0), (1), ... (45)? – Sufian Latif Sep 25 '12 at 06:43
  • 4
    On my (Swedish) keyboard I have a total of 106 letters, digits and other symbols. Take away the three Swedish letters and I can use up to base 100. That's just on the keyboard, now imagine the thousands and thousands of letters and symbols in the full Unicode range, and you can have _very_ large bases. – Some programmer dude Sep 25 '12 at 06:45
  • I have recently [written about bases](http://programmers.stackexchange.com/a/164240/10445), I also cover symbols. Maybe it helps. – phant0m Sep 25 '12 at 07:52
  • See [this](https://stackoverflow.com/questions/3973685/python-homework-converting-any-base-to-any-base) and [this](https://stackoverflow.com/a/57224753/7307096). There's a similar question there. – Shaheem TP Jul 26 '19 at 18:28

5 Answers5

5

The symbols you use for digits are arbitrary. For example base64 encoding uses 'A' to represent the zero valued digit and '0' represents the digit with the value 52. In base64 the digits go through the alphabet A-Z, then the lower case alphabet a-z, then the traditional digits 0-9, and then usually '+' and '/'.

One base 60 system used these symbols: babalonian numerals

So the symbols used are arbitrary. There's nothing that 'happens' after 36 except what you say happens for your system.

Community
  • 1
  • 1
bames53
  • 86,085
  • 15
  • 179
  • 244
5

Every base has a purpose. Usually we do base conversion to make complex computations simpler.

Here are some most popular bases used and their representation.

  • 2-binary numeral system

    used internally by nearly all computers, is base two. The two digits are 0 and 1, expressed from switches displaying OFF and ON respectively.

  • 8-octal system

    is occasionally used in computing. The eight digits are 0–7.

  • 10-decimal system

    the most used system of numbers in the world, is used in arithmetic. Its ten digits are 0–9.

  • 12-duodecimal (dozenal) system

    is often used due to divisibility by 2, 3, 4 and 6. It was traditionally used as part of quantities expressed in dozens and grosses.

  • 16-hexadecimal system

    is often used in computing. The sixteen digits are 0–9 followed by A–F.

  • 60-sexagesimal system

    originated in ancient Sumeria and passed to the Babylonians. It is still used as the basis of our modern circular coordinate system (degrees, minutes, and seconds) and time measuring (minutes and hours).

  • 64-Base 64

    is also occasionally used in computing, using as digits A–Z, a–z, 0–9, plus two more characters, often + and /.

  • 256-bytes

    is used internally by computers, actually grouping eight binary digits together. For reading by humans, bytes are usually shown in hexadecimal.

The octal, hexadecimal and base-64 systems are often used in computing because of their ease as shorthand for binary. For example, every hexadecimal digit has an equivalent 4 digit binary number.

Radices are usually natural numbers. However, other positional systems are possible, e.g. golden ratio base (whose radix is a non-integer algebraic number), and negative base (whose radix is negative).


Your doubt is whether we can convert any base to any other base after base exceeds 36 ( # of Alphabets + # of digits = 26+ 10= 36)

Taking example of 64-Base It uses A–Z(Upper case)(26), a–z(lower case)(26), 0–9(10), plus 2 more characters. This way the constraint of 36 is resolved.

As we have (26+26+10+2)64 symbols in 64-base for representation, we can represent any number in 64 base. Similarly for more base they use different symbols for representation.

Source: http://en.wikipedia.org/wiki/Radix

Kev
  • 118,037
  • 53
  • 300
  • 385
Munesh
  • 1,509
  • 3
  • 20
  • 46
3

With number systems, you are allowed to play god.

Playing god

What you need to understand is, that symbols are completely arbitrary. There is no god-given rule for "what comes after 36". You are free to define whatever you like.

To encode numbers with a certain base, all you need is the following:

  • base-many distinct symbols
  • a total order on the symbols

An arbitrary example

Naturally, there's an infinite amount of possibilities to create such a symbol table for a certain base:

Θ
ェ
す
)
0
・
_
o
や
ι

You could use this, to encode numbers with base 10. Θ being the zero-element, being the one, etc.

Conventions

Of course, your peers would not be too happy if you started using the above symbol table. Because the symbols are arbitrary, we need conventions. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 is a convention, as are the symbols we use for hexadecimal, binary, etc. It is generally agreed upon what symbol table we use for what basis, that is why we can read the numbers someone else writes down.

phant0m
  • 16,595
  • 5
  • 50
  • 82
1

The important thing to remember is that all numbers are symbolic of a value. Thus if you wanted to do that, you could just make a list containing the values at each position. After base 36, you simply run out of characters you can make a logical sequence out of. For example, if you used the Cambodian Alphabet with 70 odd characters, you could do base 80.

Snakes and Coffee
  • 8,747
  • 4
  • 40
  • 60
0

Here is the complete code I have written, hope this will help.

import java.util.Scanner;

    /* 
    * author : roottraveller, nov 4th 2017
    */

public class BaseXtoBaseYConversion {

    BaseXtoBaseYConversion() {
    }

    public static String convertBaseXtoBaseY(String inputNumber, final int inputBase, final int outputBase) {
        int decimal = baseXToDecimal(inputNumber, inputBase);
        return decimalToBaseY(decimal, outputBase);
    }

    private static int baseXNumeric(char input) {
        if (input >= '0' && input <= '9') {
            return Integer.parseInt(input + "");
        } else if (input >= 'a' && input <= 'z') {
            return (input - 'a') + 10;
        } else if (input >= 'A' && input <= 'Z') {
            return (input - 'A') + 10;
        } else {
            return Integer.MIN_VALUE;
        }
    }

    public static int baseXToDecimal(String input, final int base) {
        if(input.length() <= 0) {
            return Integer.MIN_VALUE;
        }

        int decimalValue = 0;
        int placeValue = 0;

        for (int index = input.length() - 1; index >= 0; index--) {
            decimalValue += baseXNumeric(input.charAt(index)) * (Math.pow(base, placeValue));
            placeValue++;
        }

        return decimalValue;
    }

   private static char baseYCharacter(int input) {
        if (input >= 0 && input <= 9) {
            String str = String.valueOf(input);
            return str.charAt(0);
        } else {
            return  (char) ('a' + (input - 10));
            //return  ('A' + (input - 10));
        }
    }

    public static String decimalToBaseY(int input, int base) {
        String result = "";

        while (input > 0) {
            int remainder = input % base;
            input = input / base;
            result = baseYCharacter(remainder) + result;  // Important, Notice the reverse order here
        }

        return result;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter : number baseX baseY");

        while(true) {
            String inputNumber = scanner.next();
            int inputBase      = scanner.nextInt();
            int outputBase     = scanner.nextInt();

            String outputNumber = convertBaseXtoBaseY(inputNumber, inputBase, outputBase);
            System.out.println("Result = " + outputNumber);
        }
    }
}
roottraveller
  • 7,942
  • 7
  • 60
  • 65