java中“0x”表示的含義


 

 

    public static void main(String[] args) {
        int a = 0xff;//16進制默認是int
        int b = 0x000000ff;
        System.out.println(a);//255
        System.out.println(b);//255
        //結論16進制默認是int類型,前面的的0可以省略

        //byte c = 0xff;//報錯,需要強制把int轉成byte
        byte d = 0b01;//0b默認是byte類型,前面的0可以省略
        byte e = 0b000000001;
        System.out.println(d);//1
        System.out.println(e);//1
    }

 

 

public class Test {
    
    public static void main(String[] args) {
        
        int a = 0x2f;//小寫十六進制(等價於0x002f)
        System.out.println(Integer.toBinaryString(a));
        
        int b = 0x2F;//大寫十六進制
        System.out.println(Integer.toBinaryString(b));
        
        int c = 10;//標准十進制
        System.out.println(Integer.toBinaryString(c));
        
        int d = 010;//以零開頭,表示八進制
        System.out.println(Integer.toBinaryString(d));
        
        
        
        char e = 0xff;//char為2個字節,16位
        byte f = 0xf;//byte為8位
        short g = 0xff;//short為2個字節,16位
        System.out.println(Integer.toBinaryString(e));
        System.out.println(Integer.toBinaryString(f));
        System.out.println(Integer.toBinaryString(g));
 
    }
}
/*
  結果如下:(都是按照int型處理)
101111
101111
1010
1000
11111111
1111
11111111

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM