×

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

Add Time in Java

Before Java 8, java.util.Date was one of the most usually involved classes for addressing date-time values in java. Then Java 8 presented java.time.LocalDateTime and java.time.ZonedDateTime. Java 8 likewise permits us...

6 minutes read.

Java Implements Keyword

To understand about the keyword implements we need to learn about the concept of the interfaces and inheritance in java programming languages. So let us learn about the interface and...

3 minutes read.

Pig Latin Program in Java

Pig Latin Program in Java Pig Latin is a method for translating words of the English language into a different language. It is an encrypted word that is generated by using the following steps....

4 minutes read.

&amp;&amp; Operator in Java

“ && ” is the conditional - And operator in Java. In Java, it is an example of a logical operator. In Java, the “ & ” operator has two...

3 minutes read.

Example of Static import in Java

Static keyword Java's static keyword is mainly used to control memory. Variables, methods, blocks, and nested classes are compatible with the static keyword. Instead of an instance, the static keyword is...

3 minutes read.

How to Convert String to char in Java

How to Convert String to char in Java There are two methods to convert String to char are: Using charAt() method Using tocharArray() method Using charAt() method This is the method of String class that...

3 minutes read.

How to Set Environment Variables for Java

Introduction Java is an object-oriented programming language that is based on classes and can be employed mostly to develop web and desktop applications. No matter the computer architecture, Java applications are...

7 minutes read.

Best Practices to use String Class in Java

Use String Builder or String Buffer for String concatenation in place of + operator.Compare two strings by equals( ) method instead == operator.Call .equals( ) method on a known String...

3 minutes read.

Java URL Class with Example

Java URL Uniform Resource Locator To find any resource on the internet, you need to have an address of it. The URL and IP addresses are the pointers used for this purpose....

12 minutes read.

Parallel Arrays Sort in Java

Sorting is a technique of arranging a sequence of numbers in ascending order, that is, the first number being lowest and gradually incrementing the numbers such that the last number...

7 minutes read.

Java delete directory

The File classes in Java may symbolize a directory or a file on the system. Inside the java.io package, the Files class is accessible. The File class has several helpful...

2 minutes read.

How to Develop Programming Logic in Java?

Introduction In the world of software development, Java programming language is one of the most powerful programming languages that is used to create a wide range of applications. It includes desktop,...

18 minutes read.

Split String into String Array in Java

The String split() technique returns a variety of divided strings after the strategy parts the given String around matches of a given normal articulation containing the delimiters. The ordinary articulation...

4 minutes read.

Sort Dates in Java

The Collection class's sort() method, which is a component of the Comparator mechanism, arranges the data in decreasing order. The Comparator interface can be used to accomplish the goal while...

4 minutes read.

Convert Integer to Roman Numerals in Java

The main objective of this article is to convert the integers that are decimal values to the roman numbers. Problem statement: Write a software/program/code to convert any integer to a roman number. You...

10 minutes read.

Display Unique Rows in a Binary Matrix in Java

To solve this problem, we must first locate and display the distinct rows of a supplied binary matrix afterward. We will go through how to show distinct rows inside a...

12 minutes read.

How to Convert Object to String in Java

How to Convert Object to String in Java You can convert any Object to String in Java whether it is a user-defined class, StringBuilder or StringBuffer, etc. There are two methods...

2 minutes read.

Check the presence of Substring in a String in java

In java, the string can be treated as class and datatype. The string contains words and numbers but should be in double-quotes. Example: ” Omsairam” Substring The part of the string is called...

2 minutes read.

Creation of Multi Thread in java

What are threads in Java? We can use threads to facilitate parallel processing. Threads are helpful when you wish to execute several pieces of code concurrently. A thread is a small process...

3 minutes read.

How to Concatenate Two Strings in Java

How to Concatenate Two Strings in Java Concatenation of two strings means adding the beginning of one string to the end of the other string. Some of the ways to concatenate...

3 minutes read.