java求负数补码的方法

    xiaoxiao2021-03-25  121

    public class ComplementCode { /** * 求负数的补码的方法。 注意: 负数的补码是在其原码的基础上,符号位不变,其余位取反,然后加1 * @param a * @author lhever 2017年4月4日 下午8:42:47 * @since v1.0 */ public static void printComplementCode(int a) { for (int i = 0; i < 32; i++) { // 0x80000000 是一个首位为1,其余位数为0的整数 int t = (a & 0x80000000 >>> i) >>> (31 - i); System.out.print(t); } System.out.println(); } public static void main(String[] args) { printComplementCode(-10); // 11111111 11111111 11111111 11110110 } }
    转载请注明原文地址: https://ju.6miu.com/read-24352.html

    最新回复(0)