While JavaScript might not be the ideal language to write a production compiler, you might enjoy the “Create Your Own Compiler” tutorial that does an annotated walkthrough of “The Super Tiny Compiler” ...
I have a C union of a struct containing bit-fields and an unsigned word which contains various flags and multi-bit variables within it (status register). I use the bit-fields as a quick way to access ...