Monday, October 5, 2015

Convert Java String to Binary

0 comments

Convert Java String to Binary


public class CodeSnippets 

public static StringBuilder getBinary(String value)
byte[] bytes = value.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;


return binary;




Convert Java String to Binary

0 comments:

Post a Comment