JAVA——明码

   日期:2020-11-03     浏览:100    评论:0    
核心提示:明码这段信息是(一共10个汉字):4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 016 64 16 64 34 68 127 126 66 -124 67 4 66 4 66 -124 126 100 66 36 66 4 66 4 66 4 126 4 66 40 0 164 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8

明码


这段信息是(一共10个汉字):

4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0

16 64 16 64 34 68 127 126 66 -124 67 4 66 4 66 -124 126 100 66 36 66 4 66 4 66 4 126 4 66 40 0 16

4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0

0 -128 64 -128 48 -128 17 8 1 -4 2 8 8 80 16 64 32 64 -32 64 32 -96 32 -96 33 16 34 8 36 14 40 4

4 0 3 0 1 0 0 4 -1 -2 4 0 4 16 7 -8 4 16 4 16 4 16 8 16 8 16 16 16 32 -96 64 64

16 64 20 72 62 -4 73 32 5 16 1 0 63 -8 1 0 -1 -2 0 64 0 80 63 -8 8 64 4 64 1 64 0 -128

0 16 63 -8 1 0 1 0 1 0 1 4 -1 -2 1 0 1 0 1 0 1 0 1 0 1 0 1 0 5 0 2 0

2 0 2 0 7 -16 8 32 24 64 37 -128 2 -128 12 -128 113 -4 2 8 12 16 18 32 33 -64 1 0 14 0 112 0

1 0 1 0 1 0 9 32 9 16 17 12 17 4 33 16 65 16 1 32 1 64 0 -128 1 0 2 0 12 0 112 0

0 0 0 0 7 -16 24 24 48 12 56 12 0 56 0 -32 0 -64 0 -128 0 0 0 0 1 -128 3 -64 1 -128 0 0

public class Excise { 
 public static void main(String[] args) { 
  int array[] = new int[] { 4, 0, 4, 0 ,4 ,0 ,4, 32, -1, -16, 4, 32, 4, 32, 4, 
    32, 4, 32, 4, 32, 8, 32, 8, 32, 16, 34, 16, 34, 32, 30, -64, 0, 
    16, 64, 16, 64, 34 ,68 ,127, 126 ,66 ,-124, 67, 4, 66, 4 ,66 ,-124, 
    126 ,100 ,66 ,36, 66, 4, 66, 4, 66, 4, 126, 4, 66, 40, 0 ,16,4,0,4,
    0,4,0,4,32,-1,-16,4,32,4,32,4,32,4,32,4,32,8,32,8,32,16,34,16,34,32,
    30,-64,0,0,-128,64,-128,48,-128,17,8,1,-4,2,8,8,80,16,64,32,64,-32,
    64,32,-96,32,-96,33,16,34,8,36,14,40,4,4,0,3,0,1,0,0,4,-1,-2,4,0,4,
    16,7,-8,4,16,4,16,4,16,8,16,8,16,16,16,32,-96,64,64,16,64,20,72,62,
    -4,73,32,5,16,1,0,63,-8,1,0,-1,-2,0,64,0,80,63,-8,8,64,4,64,1,64,0,
    -128,0,16,63,-8,1,0,1,0,1,0,1,4,-1,-2,1,0,1,0,1,0,1,0,1,0,1,0,1,0,5,
    0,2,0,2,0,2,0,7,-16,8,32,24,64,37,-128,2,-128,12,-128,113,-4,2,8,12,
    16,18,32,33,-64,1,0,14,0,112,0,1,0,1,0,1,0,9,32,9,16,17,12,17,4,33,
    16,65,16,1,32,1,64,0,-128,1,0,2,0,12,0,112,0,0,0,0,0,7,-16,24,24,48,
    12,56,12,0,56,0,-32,0,-64,0,-128,0,0,0,0,1,-128,3,-64,1,-128,0,0 };
  for(int i=0; i < array.length; i++) { 
   if(array[i] < 0)
   {  String bin1 = Integer.toBinaryString(array[i]).replace("0", " ");
    String bin2 = bin1.substring(24).replace("0", " ");
    if(i % 2 != 0)//起到换行作用
    { 
     System.out.println(bin2);
    }
    else
    { 
     System.out.print(bin2);
    }
   }
   else
   {  String bin3 = Integer.toBinaryString(array[i]).replace("0", " ");
    String ary[] = new String[] { " "," "," "," "," "," "," ",""};
    if(i % 2 != 0)
    { 
     System.out.println(ary[bin3.length()-1]+bin3);
    }
    else
    { 
     System.out.print(ary[bin3.length()-1]+bin3);
    }
   } 
  }
 }
}

Java中有一个Integer.toBinaryString(),他的作用是把一个10进制数转为32位的2进制数。同时对负数,会用补码表示。

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服