I have the following code:
OutputStreamBitWriter writer = new OutputStreamBitWriter(System.out);
writer.writeBit(1);
If I want to print the value or store it in a String, how do I do that?
I have the following code:
OutputStreamBitWriter writer = new OutputStreamBitWriter(System.out);
writer.writeBit(1);
If I want to print the value or store it in a String, how do I do that?
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamBitWriter writer = new OutputStreamBitWriter(out);
writer.writeBit(1);
//bla-bla
writer.flush();
System.out.println(new String(out.toByteArray()));
You need to do something like this:
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamBitWriter writer = new OutputStreamBitWriter(out);
writer.writeBit(1);
byte[] bytes = out.getBytes();
// Format and output the bytes.
Now since I suspect this is homework, I'm not going to spoon-feed you the complete solution. But here's a hint: if you try to turn the bytes into a String, the chances are that it will contain non-printing characters.