Writing to file using BitBuffer

Signed-off-by: Johnstein <joao.neto.feup@gmail.com>