反码补码源码

1.对于正数,其反码=源码=补码

例如:+7 符号位 数值为: 0000 0111

其反码=源码=补码=0000 0111

2.在计算机中,负数以其正值的补码形式表达。

对于负数,负数的反码与原码符号位相同,数值为取反。

负数的补码是在反码的基础上加1。

例如:-7 符号位 数值为: 1000 0111

源码是:1000 0111

反码是:1111 1000

补码是:1111 1001

3.char强转int

01.方法1


public
static void main(String[] args) { char numChar = '3'; int intNum = numChar - '0'; System.out.println(numChar + ": " + intNum);//3: 3 }

02.方法2

 public static void main(String[] args) {  
        char numChar = '9';  
        int  intNum = Character.getNumericValue(numChar);  
        System.out.println(numChar + ": " + intNum);  //9: 9
    }  

猜你喜欢

转载自www.cnblogs.com/lyb0103/p/9560780.html