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.

    Edited once, last by hyle ().

  • 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.

    “Es ist schon über so viele Dinge Gras gewachsen, dass man bald keiner Wiese mehr trauen kann.”

  • 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.