How to convert a string to a stream of bits in java

后端 未结 3 1991
感动是毒
感动是毒 2021-02-15 17:24

How to convert a string to a stream of bits zeroes and ones what i did i take a string then convert it to an array of char then i used method called forDigit(char,int) ,but it

3条回答
  •  青春惊慌失措
    2021-02-15 18:06

    I tried this one ..

    public String toBinaryString(String s) {
    
        char[] cArray=s.toCharArray();
    
        StringBuilder sb=new StringBuilder();
    
        for(char c:cArray)
        {
            String cBinaryString=Integer.toBinaryString((int)c);
            sb.append(cBinaryString);
        }
    
        return sb.toString();
    }
    

提交回复
热议问题