×

Vigesimal in Java

A number system with a base of 20 is known as the vigesimal in Java. A base-20 (base-score) numeric system, often known as a vigesimal system, is centered on the twenty (in the same way in which the system of the decimal numeral is based on the ten). The word vicesimal, which means "twentieth," is a derivative of Latin. Similar to Duodecimal values, we can determine the corresponding Vigesimal value of binary, octal, decimal, and hexadecimal numbers using preset or user-defined algorithms, or we may determine a corresponding Vigesimal number of other base numbers for a given Vigesimal number. The base 20 vigesimal (used by the Mayans) and base 60 sexagesimal (used by the Babylonians) number systems, as well as the base 12 duodecimal (used by the Egyptians) number system, were all utilized in ancient times.

A few illustrations of vigesimal numbers are shown here.

  • The binary value (11010111)2 corresponds to the vigesimal number (AF)20.
  • The octal number (362)8 equals to the vigesimal number (C2)20.
  • The hexadecimal value (A563E)16 is the same as the vigesimal number (44DBI)20.
  • Hexa-trigesimal number (A563E)32 is equal to the vigesimal number (36BJCE)20.

How to find a vigesimal number

The steps to determine the vigesimal number of a given hexadecimal number in any base are as follows:

  1. Consider the user's input as a hexadecimal number.
  2. To convert it to decimal, create a user-defined method.
  3. We also develop a user-defined function which thus accepts a decimal integer and changes it into a vigesimal.
  4. return the digits of the vigesimal number.

Let's put the logic for changing any hexadecimal value into a vibrational number into practice:

Let the name of the file is VigesimalNumberDemo.java

package kamalakar.com.VigesimalNumber;  
import the necessary classes and packages.
import java.util.*;  
// For the purpose of determining the corresponding vigesimal number of a given hexadecimal number, define the class VigesimalNumberDemo.
class VigesimalNumberDemo {  
    // The convertToDeci() method should be developed to return the specified hexadecimal number's decimal equivalent.
    public static String convertToDeci(String values, int base, Map<Char, Integers>hexatoDeci)  
    {  
        int sum = 0;  
        int pow = 0;  
        String tempData = values;  
          
        //logic to find equivalent decimal number  
        for (int s = tempData.length() - 1; s >= 0; s--) {  
            int valu = tempData.charAt(s) - '0';  
            if (base == 16 && hexatoDeci.containsKey(tempData.charAt(i))) {  
                val = hexatoDeci.get(tempData.charAt(i));  
            }  
            sums += (valu) * (Math.power(base, power++));  
        }  
        return String.valueOfthe(sums);  
    }  
      
    // Convert a decimal number to a vigesimal number and return the result to the main() method by creating the convertToVigesimal() method.
    public static String convertToVigesimal(String values, int base, Map<Integers, Char>decitoHexa, Map<Char, Integers>hexatoDeci)  
    {  
        String valu = values;
        int newBase = base;  
  
        // Check to see if the base is decimal.
        if (newBase != 10) {  
            // The convertToDeci() method is used if the base is not given as 10, and it returns the specified number value corresponding decimal representation.
            valu = convertToDeci(values, base, hexatoDeci);  
  
            // We modify the value of newBase to 10 after the conversion of the number.
            newBase = 10;  
        }  
          
        // string to integer conversion of the given number.
        int temp = Integers.parseInt(valu);  
        int rem;    
        String isvigesimal = "";     
          
        // In order to define the characters, build the vigesimalChar[] array.
        char vigesimalChar[] = {'A','B','C','D','E','F','G','H','I','J', 'K', '0','1','2','3','4','5','6','7','8','9'};    
          
        // finding an equivalent vigesimal number using the concept of reasoning
        while(temp > 0)    
         {    
           rem = temp % 20;     
           vigesimal = vigesimalChar[rem]+vigesimal;     
           temp = temp / 20;    
         }    
         return vigesimal;  
    }  
      
    //the main() method will be initiated here
    public static void main(String[] args)  
    {  
        // a variable to hold hexadecimal numbers should be created
        String valu;  
        // To receive input from the user, construct a scanner class object.
        Scanner sc7 = new Scanner(System.in);  
        System.out.print("The hexadecimal number to be entered is:");  
        valu = sc7.nextLine();  
          
        // object of the scanner class is closed
        Sc7.close();  
        // hexatoDeci and decitoHexa should be made to store the values.
        Map<Char, Integers> hexatoDeci = new HashMap<>();  
        Map<Integers, Char> decitoHexa = new HashMap<>();  
          
        // mechanism for storing date in hexatoDeci and decitoHexa map
        for (int s = 0; s < 6; s++) {  
            decitoHexa.put(10 + s, (char)('C' + s));  
            hexatoDec.put((char)('C' + s), 10 + s);  
        }  
          
        // Call convertToVigesimal(), then print the result of the call.
        System.out.println("The Vigesimal number : " + convertToVigesimal(valu, 16, decitoHexa, hexatoDeci)); 
    }  
}

Output:

The hexadecimal number to be entered is : C563E
The Vigesimal number : 44DBI

Other user-defined methods must be developed in order to convert base numbers other than hexadecimal, such as the convertToDeci() method, which also will convert the supplied integer in to the decimal and return it for use in computing the vigesimal number.


Related Topics

Composition in Java

Composition Java uses the composition method to implement a has-a connection. Composition allows us to reuse code in the same way that Java inheritance does. The "is-a" relationship is implemented using the...

3 minutes read.

Types of Garbage Collector in Java

Garbage collection is a Java feature that offers automatic memory management. The JVM is in charge of it. The programmer does not have to handle object creation and deallocation. We...

3 minutes read.

Zygodromes in Java

Zygodrome is a positive number created by the same digits running non-trivially. A number is called a zygodrome if identical digits constantly occur together (in pairs). The Greek word "zyg"...

4 minutes read.

How Many Ways to Create Objects in Java

Introduction Java comes under the category of object-oriented programming languages. Since it is object-oriented, everything in Java is considered an object. Java is a diverse programming language that is designed to...

6 minutes read.

How to Return Value from Lambda Expression Java?

What is Lambda Expression in Java? In Java 8, Lambda Expressions were introduced.A lambda expression is a brief section of code that accepts input and outputs a value. Similar to methods,...

4 minutes read.

Java Integer toUnsignedString() method

The toUnsignedString() method of Java Integer class returns a string representation of the argument as an unsigned decimal value. The second syntax returns a string representation of the given argument as...

2 minutes read.

How to enable java in chrome

The Java module is huge for the Java Runtime Environment (JRE). It permits a program to work with the Java stage to run Java applets. Essentially, each of the undertakings connect...

3 minutes read.

Number Pattern Programs in Java

Number Pattern Programs in Java: Number pattern programs are part of pattern programs. In the previous section, we have learned the approach to print the pattern program in Java. To...

6 minutes read.

How to set path in Java

To make programs that can run on our systems, we need to install programming language-related software in our systems. Different programming languages require different types of software, aka IDEs (Integrated Development...

5 minutes read.

Buffer reader to read string in Java

The Buffered Reader class of Java is used to read the stream of characters from the input stream. Program to read string using Buffer reader import java.io.*; class  Demo {   public static void main(String...

3 minutes read.

How to Convert int to double in Java

How to Convert int to double in Java When two variables of different types are involved in the single expression, Java compiler uses built-in library function to convert the variable to...

2 minutes read.

Java Code Coverage Tools

Code coverage testing is a crucial metric that gauges how thoroughly the program's source code has been tested. The market is flooded with Code Coverage Tools, making it difficult to...

7 minutes read.

Round Robin Scheduling Program in Java

A CPU scheduling technique is known as Round Robin (RR). Additionally, network schedulers employ it. It was created specifically for a time-sharing system. The temporal slicing scheduling algorithm is another...

4 minutes read.

Even Odd Program in Java

Even Odd Program in Java The number that are completely divisible by 2 are even and the number that leaves remainder are odd numbers. For example, the numbers 2, 0, 4,...

5 minutes read.

Magic Square in Java

A square with numbers is referred to as a magic square. The numbers in a magic square of order n are arranged to ensure that the sum of all of...

4 minutes read.

Java Future Example

Future is an interface in the Java language that is a part of  java.util.concurrent package. It serves as a symbol for the output of an asynchronous computation. The interface offers ways to determine whether a computation has finished,  wait for it to finish, and receive its result. Once the task or calculation is finished, it cannot be undone. A Future interface offers ways to determine whether the computation is finished, to wait for it to finish, and to receive the computation's results. When the computation...

3 minutes read.

Stable Marriage Problem in Java

Given N men and N women, the Stable Marriage Problem asks you to match up the men and women in such a way that there are never any two people...

6 minutes read.

Array and String with Examples in Java

Array in Java: An array in Java is a group of variables with similar types that have a common name. The arrays used in Java differ from those used in C/C++. Key...

6 minutes read.

How to check data type in Java

In this section, we will learn about the methodology to verify the data type in Java. There are mainly two methods in java called as getClass() and getName(). They are...

3 minutes read.

Java String lastIndexOf() method

Java String lastIndexOf() method returns last index of character or substring in a String. Syntax: Method Description int lastIndexOf(int ch)It returns last index position for the given char valueint lastIndexOf(int ch, int...

2 minutes read.