#need help with some code i gotta present today

13 messages · Page 1 of 1 (latest)

proper otter
#

i have gotten a code that i need to present today in front of my class. I really cant wrap my head around the code.

lusty sunBOT
#

This post has been reserved for your question.

Hey @proper otter! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

proper otter
#

this is the code

#
package com.example.s2_project_final;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.math.BigInteger;

public class Convert {
    // Funksionet e kovertimit
    @NotNull
    @Contract(pure = true)
    public static String doconvert(String inputi, String from, String to) {
        int fromBase = getBase(from);
        int toBase = getBase(to);
        BigInteger number = new BigInteger(inputi, fromBase);
        return number.toString(toBase);
    }

    private static int getBase(String vlerat) {
        return switch (vlerat) {
            case "Binar" -> 2;
            case "Decimal" -> 10;
            case "Oktal" -> 8;
            case "Heksadecimal" -> 16;
            default -> throw new UnsupportedOperationException("Invalid numeral system: " + vlerat);
        };
    }
}
#

this is supposed to turn numbers into other types of numbers (decimal numbers to binary, octal, hexadecimal and vise versa)

bleak cosmos
#

Alright

#

What part is it you don't understand?

proper otter
#

the part of the conversion of the numbers from one to the other

#

i dont see where that happens

#

is it a part of the library of the bigint or idk

bleak cosmos
#

Yes it is

#

It happens at

number.toString(toBase)