[160909][Java]二进制编辑器

来源:互联网 发布:wind万德数据库官网 编辑:程序博客网 时间:2024/05/20 21:18
package com.xiaotustudio;import java.math.BigInteger;public class Main{    public static void main(String[] args)    {        String s="哈哈哈";        byte[] bytes=s.getBytes();        BigInteger bigInteger = new BigInteger(1, bytes);        String result=bigInteger.toString(2).toUpperCase();        for(int i=0;i<result.length();i++)        {            if(i%8!=7)            {                System.out.print(result.charAt(i));            }            else            {                System.out.println(result.charAt(i));            }        }        result=bigInteger.toString(16).toUpperCase();        for(int i=0;i<result.length();i++)        {            if(i%2==0)            {                System.out.print(result.charAt(i));            }            else            {                System.out.print(result.charAt(i)+" ");            }        }    }}

0 0