• 2进制转化成字符串


        public static void main(String[] args) {
            System.out.println(StrToBinstr("你好"));
            System.out.println(new StringToBean().BinstrToStr("100111101100000 101100101111101"));
            
        }
           //将Unicode字符串转换成bool型数组
       
       
        //将二进制字符串转换成Unicode字符串-------
        private String BinstrToStr(String binStr) {
            String[] tempStr=StrToStrArray(binStr);
            char[] tempChar=new char[tempStr.length];
            for(int i=0;i<tempStr.length;i++) {
                tempChar[i]=BinstrToChar(tempStr[i]);
            }
            return String.valueOf(tempChar);
        }
       
        
       
        //将二进制字符串转换为char------
        private char BinstrToChar(String binStr){
            int[] temp=BinstrToIntArray(binStr);
            int sum=0;   
            for(int i=0; i<temp.length;i++){
                sum +=temp[temp.length-1-i]<<i;
            }   
            return (char)sum;
        }
        //将初始二进制字符串转换成字符串数组,以空格相隔----------
        private String[] StrToStrArray(String str) {
            return str.split(" ");
        }
        //将二进制字符串转换成int数组---------
        private int[] BinstrToIntArray(String binStr) {       
            char[] temp=binStr.toCharArray();
            int[] result=new int[temp.length];   
            for(int i=0;i<temp.length;i++) {
                result[i]=temp[i]-48;
            }
            return result;
        }
        private static String StrToBinstr(String str) {
            char[] strChar=str.toCharArray();
            String result="";
            for(int i=0;i<strChar.length;i++){
            result +=Integer.toBinaryString(strChar[i])+ " ";
            }
            return result;
        }

  • 相关阅读:
    ORACLE DROP TABLE和truncate table的区别
    C#版链表加强版
    C#版栈
    再谈为什么要使用MONO
    流浪猫伏击大白鹅
    编写ASP.NET复合控件实例
    C# 大文件拷贝
    关于团队项目构架设计的疑问
    在Windows平台下使用MONO
    C#版链表
  • 原文地址:https://www.cnblogs.com/aiwoqu/p/4308855.html
Copyright © 2020-2023  润新知