作业题不会时,搜题看到的让人很迷的代码,留待以后解决

来源:互联网 发布:哑铃品牌知乎 编辑:程序博客网 时间:2024/05/21 05:57

2. . 请写出10000101的补码计算过程和结果11111011

public class PrintBinary {

   public static void main(String args[]){

      PrintBinary s=new PrintBinary();

      s.printBinaryInt(256);

      s.printBinaryInt(~256);

   }

   void printBinaryInt(int i){

      for(int j=31;j>=0;j--)

          if(((1<<j)& i)!=0)

              System.out.print("1");

          else

              System.out.print("0");

          System.out.println();

     

   }

}

最后附上滔哥认真学习和潇洒的图片镇楼



阅读全文
0 0
原创粉丝点击