As an exercise, I am attempting to implement an assembler for a self-defined fictitious architecture.
The only thing I'm unsure of is how to actually generate the bits. Each of my machine instructions are 2 bytes long.
For example, say I have determined that I need to generate the following byte code:
0100000100110001
This is a situation where I'm building the instruction a chunk at a time, for example, the first 3 bits are the op code, then there's some reserved bits, then a flag etc.
I figure it would be easiest to construct it as a literal string.
How can I convert a string, e.g. '0100000100110001' into the corresponding bit string and then write it to a file directly, without changing the byte ordering?
I think I might be able to use the ByteArray constructor, but I can't find any suitable examples in the docs.