logic for bin parse and write - works on win and linux. need to test mac