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.

    “Sometimes it's better to light a flamethrower than curse the darkness.” — Terry Pratchett, Men At Arms