i want to retrieve the binary values of the data in the file. so i have written the following the code:
while ((fileData = br.readLine()) != null) {
byte b[] = fileData.getBytes("UTF-8");
BigInteger bi = new BigInteger(b);
String s = bi.toString(2);
System.out.println("Original message in binary: " + s);
System.out.println("Original message length: " + s.length());
}
output:
abca (this is the data in a text file)
Original message in binary: <here>1100001011000100110001101100001
Original message length: 31
Everything is fine but while i am printing the data in binary format i am not able to print the first bit (<here>) can anyone help me?
For first character:
EDIT:
If you want to print the binary representation of first byte then try this:
EDIT 2:
Try this for leading zeroes.
and call as