-1

So, Supposing I have the byte set

0101 0101 0110 0010 1101 0100 1111 0010 1011 0010 0101 1010

How would I do to get every byte independently? For example, printing them so the output is:

0101
0101
0110
0010
1101
0100
1111
1101
0010
1011
0010
0101
1010

Thanks a Lot!

Some Code:

protected String parse(StringBuilder builder) {

    String pBinary = getBinary(p);
    String qBinary = getBinary(q);
}

private String getBinary(BigInteger integer) {
    StringBuilder builder = new StringBuilder();

    for (byte bytes : integer.toByteArray()) {
        builder.append(" ");

        String binary = Integer.toBinaryString(Byte.toUnsignedInt(bytes));

        if (binary.length() != 8)
            for (int i = binary.length(); i < 8; i++)
                builder.append(0);

        builder.append(binary);
    }

    return builder.substring(1);
}

p and q are BigIntegers.

The idea is to insert at the start of the StringBuilder a "Mixture" of both binaries.

So if binary 1 is 01101001 01010111 and binary 2 is 10111010,

the mixture will result in 01101001 00000000 01010111 10111010

Holger
  • 285,553
  • 42
  • 434
  • 765
Juanco
  • 33
  • 1
  • 6

1 Answers1

1

If you have a string that has words separated by spaces you can do

String[] words = myString.split("\\s+")

More detailed answer here, How do I split a string with any whitespace chars as delimiters?

Community
  • 1
  • 1
francium
  • 2,384
  • 3
  • 20
  • 29