String To Binary Conversion using java.....


Hi Friends, Here the logic for "String to Binary(8 bit)" conversion



Save the file Binary.java



class Binary

{

public static void main(String[] args)

{

String msg = "Hello";           //coverted String...



byte[] bytes = msg.getBytes();             //getting byte values



StringBuilder binary = new StringBuilder();



int msgg = 0;



for (byte b : bytes)

{

int val = b;

for (int i = 0; i < 8; i++)

{

binary.append((val & 128) == 0 ? 0 : 1);



   val <<= 1;



}



}



System.out.println("'" + msg + "' to binary: " + binary);

       }

}



I hope it is usefulll....





Comments

Popular posts from this blog

Android App Version Update using the following cordova cli commands

75 inspirational quotes that will change your life

Retrieval Image From DataBase and Display on WebPage by Using Servlets.