SSISO Community

시소당

메서드를 이용한 (2,8,10,16)진수 변환

class  BinOctHex
{
        public  static  void  main  (String[]  args)
        {
                int  a=0xC;            //16진수  직접입력
                int  b=10;                //10진수
                int  c=023;            //8진수  직접입력

  

                //2진수의  직접입력은  안되더군요  ^^;;  방법  알고  계신분은  덧글에  남겨주시는  센스!!
                
                System.out.println("10진수  a,b,c  =  "+a+"  "+b+"  "+c);
              
                System.out.println("2진수  a  =  "+Integer.toBinaryString(a));
                System.out.println("2진수  b  =  "+Integer.toBinaryString(b));
                System.out.println("2진수  c  =  "+Integer.toBinaryString(c));
              
                System.out.println("8진수  a  =  "+Integer.toOctalString(a));
                System.out.println("8진수  b  =  "+Integer.toOctalString(b));
                System.out.println("8진수  c  =  "+Integer.toOctalString(c));
              
                System.out.println("16진수  a  =  "+Integer.toHexString(a));
                System.out.println("16진수  b  =  "+Integer.toHexString(b));
                System.out.println("16진수  c  =  "+Integer.toHexString(c));
        }
}

2911 view

4.0 stars