fixed binary encoding to conform to the spec