Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASCii to BInary Conversion Program in java [duplicate]

I am currently working on a project that would convert ASCii string text into Binary digits, but I've come upon several issues. First off, I would like to know exactly how can I take single digit from a String and print out it's Binary offspring, secondly What would be the best method of applying this? Thanks

like image 837
TechTitan Avatar asked Jul 11 '26 07:07

TechTitan


1 Answers

public static String AsciiToBinary(String asciiString){  

          byte[] bytes = asciiString.getBytes();  
          StringBuilder binary = new StringBuilder();  
          for (byte b : bytes)  
          {  
             int val = b;  
             for (int i = 0; i < 8; i++)  
             {  
                binary.append((val & 128) == 0 ? 0 : 1);  
                val <<= 1;  
             }  
            // binary.append(' ');  
          }  
          return binary.toString();  
    }  
like image 113
constantlearner Avatar answered Jul 13 '26 20:07

constantlearner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!