Java binary to decimal conversion

  • I have to create a software that converts bits to decimal. When I enter a bit, it merely returns 0.0. I'm at a loss as to why. I know it's really easy, but I'm not seeing it. Any assistance would be much appreciated.

    Einmal editiert, zuletzt von hyle (25. Januar 2023 um 08:47)

  • shamzi097 Somehow I don't get why there is a question at all because the link contains several solutions to the problem. Or was the real intention to place this link here, i.e. link spam‽

    Simplest solution may be this one:

    Java
    import java.util.Scanner;
    
    public final class Test {
        private Test() {}
    
        public static void main(String... args) {
            System.out.println(Integer.parseInt(new Scanner(System.in).next(), 2));
        }
    }

    Tell Alle Zeichen ausser 1 als 0 anzusehen ist ein bisschen unsauber IMHO.

    “Dawn, n.: The time when men of reason go to bed.” — Ambrose Bierce, “The Devil's Dictionary”

  • shamzi097 Somehow I don't get why there is a question at all because the link contains several solutions to the problem. Or was the real intention to place this link here, i.e. link spam‽

    (I know i just did not get the question so just wanted to get solution in detail thats all and about the link i put is because i wanted to share the source where i read about it and i am doing course from here thats why, thanks for your help)

    Simplest solution may be this one:

    Java
    import java.util.Scanner;
    
    public final class Test {
        private Test() {}
    
        public static void main(String... args) {
            System.out.println(Integer.parseInt(new Scanner(System.in).next(), 2));
        }
    }

    Tell Alle Zeichen ausser 1 als 0 anzusehen ist ein bisschen unsauber IMHO.

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!