Reformat and rewrite write_binary() part 1